PDA

View Full Version : Problems with percentage bar


PokePets
01-09-2011, 04:52 AM
So, i want to make a percentage bar ( totalclicks / clicksrequired for next level)

This is the orginal code;
<?php
$c1 ="10";
$c2 ="13";
if($c1 == $c2)
{
$c1 = "100";
$c2 = "100";
}
if($c1 > $c2){
$c2 = $c1/$c2;
$c2 = 100/$c2;
$c1 = 100-$c2;
}
if($c1 < $c2)
{
$c1 = $c2/$c1;
$c1 = 100/$c1;
$c2 = 100-$c1;
}

$c1 = round($c1);
$c2 = round($c2);
$c2 = $c2+$c1;
$c1 = $c1*2;
$c2 = $c2 *2;

ob_start();
header("Content-Type: image/png");
$x = 200 ;
$y = 20 ;
$imgp = imageCreate($x, $y);
$random = imageColorAllocate($imgp, 230, 255, 232);
$rand = imageColorAllocate($imgp, 208,230,255);
ImageFilledRectangle ($imgp, 0, -19, $c1, 190, $rand);
ImageFilledRectangle ($imgp, $c1, -19, $c2, 190, $random);
imagePng($imgp);
imageDestroy($imgp);
ob_end_flush();
?>

& this is what i made from it xD
<?php

$id = $_GET["id"];
$id = preg_replace("/[^a-zA-Z0-9s]/", "", $id);
$id = secure($id);

// Check that ID exists and is valid

if(is_numeric($id)){

// The ID appears to be valid, so double check...

$query = "SELECT * FROM ".$prefix."owned_adoptables WHERE aid='$id'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$query2 = "SELECT * FROM ".$prefix."levels WHERE adoptiename='$type' and thisislevel='$nextlevel'";
$result2 = mysql_query($query);
$num2 = mysql_numrows($result);

//Loop out code
$i=0;
while ($i < 1) {



$aid=@mysql_result($result,$i,"aid");
$currentlevel=@mysql_result($result,$i,"currentlevel");
$type=@mysql_result($result,$i,"type");
$totalclicks=@mysql_result($result,$i,"totalclicks");
$requiredclicks=@mysql_result($result2,$i,"requiredclicks");


$c1 ="$totalclicks";
$c2 ="$requiredclicks";
if($c1 == $c2)
{
$c1 = "100";
$c2 = "100";
}
if($c1 > $c2){
$c2 = $c1/$c2;
$c2 = 100/$c2;
$c1 = 100-$c2;
}
if($c1 < $c2)
{
$c1 = $c2/$c1;
$c1 = 100/$c1;
$c2 = 100-$c1;
}

$c1 = round($c1);
$c2 = round($c2);
$c2 = $c2+$c1;
$c1 = $c1*2;
$c2 = $c2 *2;

ob_start();
header("Content-Type: image/png");
$x = 200 ;
$y = 20 ;
$imgp = imageCreate($x, $y);
$random = imageColorAllocate($imgp, 230, 255, 232);
$rand = imageColorAllocate($imgp, 208,230,255);
ImageFilledRectangle ($imgp, 0, -19, $c1, 190, $rand);
ImageFilledRectangle ($imgp, $c1, -19, $c2, 190, $random);
imagePng($imgp);
imageDestroy($imgp);
ob_end_flush();
?>

I get this error;
Parse error: syntax error, unexpected $end in /home/a2850873/public_html/EXPbalkje.php on line 71

& i think if it is fixed it will still not work ;s
I want images like siggy.php;
www.yoursite.com/percentagebar.php?id=1 shows the percentage bar of the adoptable with id 1.

Already thanks for your help ;)

Hall of Famer
01-09-2011, 11:16 AM
Apparently you forgot to enclose this if statement and your while loop with } symbols:


if(is_numeric($id)){

while ($i < 1) {

You have five { symbols but only three }, which is not consistent with PHP syntax. Try to add two more } to the appropriate locations of your php file and it should work then.

Edit: Guess you've figured out how to resolve this syntax error? Thats good, have fun coding!