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.'" />';

?>

Link to comment
Share on other sites

<?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.'" />';

?>

Link to comment
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.