NamePros.Com (http://www.namepros.com/)
-   CODE (http://www.namepros.com/code/)
-   -   Create a table/css/div bar dynamically with php (http://www.namepros.com/code/102832-create-table-css-div-bar-dynamically.html)

axilant 06-29-2005 01:22 PM

Create a table/css/div bar dynamically with php
 
Alright with my new project, i needed to use a bar to show a user how much space he/she is using... and i thought i would share this great function.
PHP Code:
<?
    
function create_bar($width, $show_text = '')
    {
        
$bar = '';    
        if (
strstr($width, '%') )
        {
            
$width = intval(str_replace('%', '', $width));
            if(
$width > 0)
            {
                
$width = ( intval($width) <= 100 ) ? $width . '%' : '100%';
            }
        }
    
        if(
$width > 0)
        {
            
$bar = "<table width=\"100\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"10\">\n";
            
$bar .= "\t<tr>\n\t\t<td width=\"100%\" align=\"left\" style=\"border: 1px solid #AAAAAA; background-color: #CECECE;\" nowrap=\"nowrap\">";
            
$bar .= "\n\t\t\t<div style=\"background-color: #26E81C; margin: 2px; height: 10px; width: {$width}px;\">";
            if (
$show_text != "")
            {
                
$bar .= "\n\t\t\t\t<span style=\"font-size: 10px;\">$show_text</span>";
            }    
            
$bar .= "\n\t\t\t</div>\n\t\t</td>\n\t</tr>\n</table>";
        }    
           return
$bar;
    }
    print(
create_bar("10","10/100"));
?>

Create_bar(int percentage used..., string for text in the middle of the bar)

all comments/suggestions welcome...

i386 06-29-2005 01:53 PM

Cool, thanks for sharing!

hasif 06-30-2005 12:56 AM

before i use i wanna look at this in demo, is there anywhere you have installed this so that i can view.


All times are GMT -7. The time now is 03:12 AM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0