Jump to content

Put the results of a while loop into a image?


Mr Chris

Recommended Posts

Hi, I have a simple while loop where I call out two sets of rows $name and $value.  Basically what I want to do is take however many come out of this query and dynamically stick them in the image below But i'll never know how many items will be called from that while loop, it could be five, or it could be 50.  Anyone please help

 

<?php

$SQL = "Select * from table";
$RESULT = mysql_query ($SQL) OR die(mysql_error());
while($ROW=mysql_fetch_assoc($RESULT)) {

  $name = $ROW['name'];
  $value = $ROW['value'];

}

//Want to take all the values from name and value from the while loop and stick them in a google chart like so. But won't know how may there are ?? */
echo '<img border="0" src="http://chart.apis.google.com/chart?cht=p3&chco=17186B,348017,CC0000&chd=t:$,'.$value.','.$value.','.$value.'&chs=500x200&chl='.$name.'|'.$name.'|'.$name.'" />';

?>

<?php

$SQL = "Select * from table";
$RESULT = mysql_query ($SQL) OR die(mysql_error());
$names = array();
$valuess = array();
while($ROW=mysql_fetch_assoc($RESULT))
{
  $names[] = $ROW['name'];
  $values[] = $ROW['value'];
}

$nameStr = implode('|', $names);
$valueStr = implode(',', $values);

//Want to take all the values from name and value from the while loop and stick them in a google chart like so. But won't know how may there are ?? */
echo '<img border="0" src="http://chart.apis.google.com/chart?cht=p3&chco=17186B,348017,CC0000&chd=t:$,'.$valueStr.'&chs=500x200&chl='.$nameStr.'" />';

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.