Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Php/Mysql array for google charts

Status
Not open for further replies.

Korizon67

Programmer
Apr 25, 2007
36
US
Hi all,

i am trying to make an array that looks like this ...

40,55,40,55,56,122,652,37

i can create 40,55,40,55,56,122,652,37, with an echo.

I have always echoed for html, now i need to store the 40,55,40,55,56,122,652,37, then i was going to use sub_str() to remove the last comma.

the thing i am not sure about is, how do i do the same as echo but instead, store it in a variable? normally I use

Code:
while ($r= mysql_fetch_array($userqry1))
{
echo $r['COUNT(BestTime)'] . ",";
}
I thought it would be something like
Code:
while ($r= mysql_fetch_array($userqry1))
{
$variable .=$r['COUNT(BestTime)'] . ",";
}
But that crashed apache2 lol.

I guess all i am attempting is to write to a variable to echo later. I am using it for google charts, it requires the commas between variables as follows...

Code:
<img src="[URL unfurl="true"]http://chart.apis.google.com/chart?cht=p3&chd=t:1057,1,1&chs=335x100&chl=Assignable[/URL] (1057)|Unfiltered (1)|Hot (1)&chf=bg,s,E1FDFC&chco=0000ff">

I am attempting to do this...

Code:
<img src="[URL unfurl="true"]http://chart.apis.google.com/chart?cht=p3&chd=t:<?[/URL] echo $variable1;?>&chs=335x100&chl=<? echo $variable2;?>&chf=bg,s,E1FDFC&chco=0000ff">

Thanks for trying to work out my garbled question!

Mike
 
i can't easily derive what you're asking for through an analysis of the code snips with the array values you provide.

so here are some generic responses for you

Code:
//to create the array
$array = array(40,55,40,55,56,122,652,37);

//you can check the array through this
echo "<pre>" . print_r($array, true) . "</pre>";

//to get this array into a comma separated string
$string = implode (',', $array);

echo $string . "<br/>";

//if you have an additional comma at the end of your string
//eg
$string = "40,55,40,55,56,122,652,37,";
//you can get rid of the comma thus
echo rtrim($string , ',');
echo "<br/>";
//this will work if there are 20 commas too
$string .= ',,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,';
echo $string;
echo "<br/>";
echo rtrim($string,',');

see the manual for references on
Array()
print_r()
rtrim()
implode()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top