Jump to content

Recommended Posts

Hi everyone,

 

I'd like to make a progress bar like this one:

progress.php?score=0progress.php?score=30progress.php?score=70progress.php?score=100

 

When you look at the URL you can choose a number from 0 to 100. 100 is a full bar and 0 is an empty bar. I'd like to make this too, but the only php bar tutorials I can find are upload bars. That's not what I need! I want a bar like this where the user can choose how much the bar is filled. How can I do this? ???

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/
Share on other sites

  • Replies 72
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Using GET method or SESSIONS.

 

<?php
if (isset($_GET['status'])) {
    if ($_GET['status'] < 25) {
        $bar = 'no-bar.jpg';
    }elseif ($_GET['status'] < 50) {
         $bar = 'quarter-bar.jpg';
    }elseif ($_GET['status'] < 75) {
         $bar = '3quarter-bar.jpg';
    }elseif ($_GET['status'] <= 100) {
         $bar = 'ful-bar.jpg';
    }
}else {
   $bar = 'no-bar.jpg';
}

echo '<img src="' . $bar . '" />';
?>

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264003
Share on other sites

Using GET method or SESSIONS.

 

<?php
if (isset($_GET['status'])) {
    if ($_GET['status'] < 25) {
        $bar = 'no-bar.jpg';
    }elseif ($_GET['status'] < 50) {
         $bar = 'quarter-bar.jpg';
    }elseif ($_GET['status'] < 75) {
         $bar = '3quarter-bar.jpg';
    }elseif ($_GET['status'] <= 100) {
         $bar = 'ful-bar.jpg';
    }
}else {
   $bar = 'no-bar.jpg';
}

echo '<img src="' . $bar . '" />';
?>

 

Do I have to enter 100 bar images? or does the echo do the filled bar between half bar and 3 quarter bar and like that?

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264032
Share on other sites

this is an example using gd to do all the work.

 

this example is my code that each time a users profile get looked at the result is displayed as a bar.

 



//this gets put on the page where the members area is to see the sats put it on a nice profile page.

<?php session_start();

$db=mysql_connect("localhost","xxxx","xxxx");
mysql_select_db("xxxx",$db);



$query5 = "SELECT `jan`, `feb`, `mar`, `apr`, `may`, `jun`, `jul`, `aug`, `sep`, `oct`, `nov`, `dec` FROM hits where id='$id'";

$result5 = mysql_query($query5);

while($data = mysql_fetch_assoc($result5)){

echo "<table>\n";
foreach ($data as $month => $hits) {
    echo "<tr>
            <td>$month</td>
            <td><img src='bar.php?val=$hits&max=1000'></td>
            <td>$hits</td>
            </tr>\n";
}
}
echo "</table>\n";
?>




//this is bar.php that produces the stats image and links to the above.



<?php
// set dimensions
     $w = 300;
     $h = 12;
// create image
     $im = imagecreate($w, $h);
// set colours to be used
     $bg = imagecolorallocate($im, 0xE0, 0xE0, 0xE0);
     $black = imagecolorallocate($im, 0x00, 0x00, 0x00);
     $barcolor  = imagecolorallocate($im, 0xFF, 0xFF, 0x00);
// draw border
     imagerectangle($im, 0,0,$w-1,$h-1,$black);
// get value and max value from query string
     $val = $_GET['val'];
     $max = $_GET['max'];
// calculate dimensions of inner bar
     $barw = $max ? floor(($w-2) * $val / $max) : 0;
     $barh = $h - 2;
// draw inner bar
 if ($barw)
     	imagefilledrectangle($im, 1, 1, $barw, $barh, $barcolor);
// send image header
     header("content-type: image/png");
// send png image
     imagepng($im);
     imagedestroy($im);
?>



//this link goes on a page that shows the search profile results.


<a href='profile.php?name=<?echo $record['name'];?>&cmd=hit'>


//make the following database.

id smallint(5)  UNSIGNED ZEROFILL Yes NULL                
  jan varchar(100)  No                 
  feb varchar(100)  No                 
  mar varchar(11)   No                 
  apr varchar(100)  No                 
  may varchar(100)  No                 
  jun varchar(100)  No                 
  jul varchar(100)  No                 
  aug varchar(100)  No                 
  sep varchar(100)  No                 
  oct varchar(100)  No                 
  nov varchar(100)  No                 
  dec varchar(11)   No 


//this goes on the page that the prfile of the member your looking at is.
<?php session_start();

$db=mysql_connect("localhost","xxx","xxx");
mysql_select_db("xxxx",$db);

$name=$_GET['name'];

$query="select * from xxxxx where name='xxxx'";
$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

if($_GET['cmd']=="hit"){

$colname=($_POST['colname']);

$colname=date('M');

$query1="select * from hits where id='".$record['id']."'";
$result1=mysql_query($query1)or die("query problam");

if(!mysql_num_rows($result1)){

$id=$record['id'];
$jan="1";
$feb="1";
$mar="1";
$apr="1";
$may="1";
$jun="1";
$jul="1";
$aug="1";
$sep="1";
$oct="1";
$nov="1";
$dec="1";

$insert="insert into hits (`id`, `jan`, `feb`, `mar`, `apr`, `may`, `jun`, `jul`, `aug`, `sep`, `oct`, `nov`, `dec`)values('$id','$jan','$feb','$mar','$apr','$may','$jun','$jul','$aug','$sep','$oct','$nov','$dec')";
$in=mysql_query($insert)or die("insert problam");

}elseif(mysql_num_rows($result1)>0){

$update="update hits set $colname=$colname+1 where id='".$record['id']."'";


$resultu=mysql_query($update)or die("update problam");
}
}
?> 

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264036
Share on other sites

Using GET method or SESSIONS.

 

<?php
if (isset($_GET['status'])) {
    if ($_GET['status'] < 25) {
        $bar = 'no-bar.jpg';
    }elseif ($_GET['status'] < 50) {
         $bar = 'quarter-bar.jpg';
    }elseif ($_GET['status'] < 75) {
         $bar = '3quarter-bar.jpg';
    }elseif ($_GET['status'] <= 100) {
         $bar = 'ful-bar.jpg';
    }
}else {
   $bar = 'no-bar.jpg';
}

echo '<img src="' . $bar . '" />';
?>

 

Do I have to enter 100 bar images? or does the echo do the filled bar between half bar and 3 quarter bar and like that?

 

Using that code yes, to avoid that use the image functions to create the images. Best bet if that is what you want.

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264039
Share on other sites

Ok, I'm using this code. I still have to make the bar images and change every bar.jpg to the correct bar.

<?php
if (isset($_GET['status'])) {
    if ($_GET['status'] < 1) {
        $bar = 'bar1.jpg';
    }elseif ($_GET['status'] < 2) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 3) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 4) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 5) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 6) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 7) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] <  {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 9) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 10) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 11) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 12) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 13) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 14) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 15) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 16) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 17) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 18) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 19) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 20) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 21) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 22) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 23) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 24) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 25) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 26) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 27) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 28) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 29) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 30) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 31) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 33) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 34) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 35) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 36) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 37) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 38) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 39) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 40) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 41) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 42) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 43) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 44) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 45) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 46) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 47) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 48) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 49) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 50) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 51) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 52) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 53) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 54) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 55) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 56) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 57) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 58) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 59) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 60) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 61) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 62) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 63) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 64) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 65) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 66) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 67) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 68) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 69) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 70) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 71) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 72) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 73) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 74) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 75) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 76) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 77) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 78) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 79) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 80) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 81) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 82) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 83) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 84) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 85) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 86) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 87) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 88) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 89) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 90) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 91) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 92) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 93) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 94) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 95) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 96) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 97) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 98) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] < 99) {
         $bar = 'bar.jpg';
    }elseif ($_GET['status'] <= 100) {
         $bar = 'bar.jpg';
    }
}else {
   $bar = 'bar0.jpg';
}

echo '<img src="' . $bar . '" />';
?>

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264059
Share on other sites

The following is a quick PHP/HTML script I just put together that utilizes CSS to draw a progress bar. See if it can fit into your script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Progress Bar Test</title>
<style>
.bar {
  display: block;
  width: 50%;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid black;
  height: 1em;
}
.pbar {
  display: block;
  background-color: green;
  float: left;
  height: 1em;
}
</style>
</head>
<body>
<div class="bar">
<?php
  $pbar_width = (isset($_GET['w']))?$_GET['w']:10;
  echo '<span class="pbar" style="width:' . $pbar_width . '%;"> </span>';
?>
<div style="clear:both;line-height:0.01em"> </div>
</div>
</body>
</html>

 

I've uploaded the test script to http://www.rbnsn.com/phpfreaks/progress_bar.php

 

Try it with different value of "w" on the url:

http://www.rbnsn.com/phpfreaks/progress_bar.php?w=99

http://www.rbnsn.com/phpfreaks/progress_bar.php?w=1

http://www.rbnsn.com/phpfreaks/progress_bar.php?w=45

http://www.rbnsn.com/phpfreaks/progress_bar.php?w=49.9

http://www.rbnsn.com/phpfreaks/progress_bar.php?w=50.1

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264061
Share on other sites

Change:

.bar {
  display: block;
  width: 50%;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid black;
  height: 1em;
}

to

.bar {
  display: block;
  width: 102px;
  margin-left: auto;
  margin-right: auto;
  border: 1px solid black;
  height: 12px;
}

 

You might want to remove the "margin-left" and "margin-right" attributes. Those are there to center the bar on the page.

 

In my example, I used "w" on the URL, just use "score" instead.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/53430-solved-progress-bar/#findComment-264089
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.