Help with simple php code

Hello, its me again with simple problem…
In my last topic i had problem because my mysql wasnt updated but with daveismyname’s help i solved my problem.

When i tried to display its something like this http://img163.imageshack.us/img163/895/77ee17f9a5074712ba3bb89.png
Problem is because the procentage go up, also the error Up is ‘The server wasnt send any informations and on bottom i want show old resultats’

Code looks like this
[php]$query = “SELECT SUM(Glasaci) FROM glasanje”;
$result = mysql_query($query);
$a = mysql_fetch_array($result);
$a[‘SUM(Glasaci)’];[/php]
This get the sum of all votes…

[php]function zemi_procent($broj,$od)
{
$procent = round($broj * 100 / $od);
echo $procent;
}[/php]
toa get procentage

and

[php]$rezultat = mysql_query(“SELECT * FROM glasanje”);
while($row = mysql_fetch_array($rezultat))
{
echo “

”.$row[‘Ime’]."

".zemi_procent($row[‘Glasaci’], $a[‘SUM(Glasaci)’])."% -".$row[‘Glasaci’]." Гласачи";
}
}[/php]
the result of mysql . $row[‘Ime’] the name , .$row[‘Glasaci’] means votes from one like(prekrasno or super) and the sum

From what i can see, you’re not giving the zemi function all the parameters. I don’t see anything that defines what $od is. If you’re going use mysql_fetch_array(), then you’ll need to use a loop to get the information, else use mysql_fetch_assoc.

$od means the sum of all votes

You’re calling it wrong though. [php]
$query = “SELECT SUM(Glasaci) FROM glasanje”;
$result = mysql_query($query);
$a = mysql_fetch_array($result);
//$a[‘Glasaci’]; nothing is being done with this

$rezultat = mysql_query(“SELECT * FROM glasanje”);
while($row = mysql_fetch_array($rezultat)) {
echo “

”.$row[‘Ime’]."

".zemi_procent($row[‘Glasaci’], $a[‘Glasaci’])."% -".$row[‘Glasaci’]." Гласачи";
}[/php]

You don’t need to put SUM() in the variable, just in the query.

sorry, buy i cant understand your mean, i just know because the result is good, i think the php is giving good procents , but my problem is becouse the procents go up :confused:

I think its because of this - $a[‘SUM(Glasaci)’]. try it without the SUM in there

echo “

”.$row[‘Ime’]."

".zemi_procent($row[‘Glasaci’], $a[‘Glasaci’])."% -".$row[‘Glasaci’]." Гласачи";

or it could also be the query, since $row[‘Glasaci’] is a single number, not the value in the row. if you want to do that, then change the query too

$query = “SELECT SUM(Glasaci) Glas, Glasaci FROM glasanje”;

Then change the function call to

zemi_procent($row[‘Glas’], $a[‘Glasaci’])

That may fix it the recurring percentage problem.

ok thanks, i will try

nothing changed, the procents go up again

i replace ECHO with RETURN on my function and now its works :slight_smile: thanks to all replies :slight_smile:

The dpi and image size doesnt matter but the compression comes at the end. If you are saving as a regular JPG a little box will come up that will ask for quality. It has a slider from 1 - 12 1 being highly compressed 12 being little compression. You will want to save the image with the slide at 10-12 for the best quality. If you are Saving For Web then look to the right you will see the JPG options and a quality number 1-100 you will want this to be 80 or higher for a good quality.

That should fix your compression issues.

Sponsor our Newsletter | Privacy Policy | Terms of Service