Rifts Posted October 14, 2010 Share Posted October 14, 2010 Ok so I'm trying to use jpgraph which allows you to make graphs with php (you dont need to know anything about jpgraph to help me) anyway how it works is this line data = array(1,3,4,5); the numbers here are what the graph plots. now i'm trying to figure out a way to place values from my database in there. the problem is the amount of values is constantly changing. I tried a lot of things but nothing is working here is my last try: $result = mysql_query("SELECT thismonth FROM list"); while ($row = mysql_fetch_array($result)) { $data[] = $row[0]; } $number = count($data); for ($i = 0; $i < $number; $i++) { $wtf .= $data[$i] . ',' ; } now when i echo $wtf i get values such as 6,3,2,0,1 now i tried this $data = array($wtf); but it doesnt work any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2010 Share Posted October 14, 2010 $data is already an array with values (1,3,4,5,x,y,z,...) Your $wtf is a string and putting a string into an array makes it the data in the first element of the array. Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122303 Share on other sites More sharing options...
Rifts Posted October 14, 2010 Author Share Posted October 14, 2010 im trying to replace that original $data = array(x,x,xx,) by putting the values pulled from the db into an array and then setting that new array to $data but i cant figure it out Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122306 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2010 Share Posted October 14, 2010 Replace what original $data array? $data IS an array of the values pulled from your database. Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122308 Share on other sites More sharing options...
Rifts Posted October 14, 2010 Author Share Posted October 14, 2010 im sorry i think i didnt explain it clearly, the line data = array(1,3,4,5); is not dynamic i just wrote that line out. what i actaully need would be like this $data - array(databasevalue1, databasevalue2, databasevaule3, etc.) Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122311 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2010 Share Posted October 14, 2010 What do you think the following line of code does? - $data[] = $row[0]; Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122313 Share on other sites More sharing options...
Rifts Posted October 14, 2010 Author Share Posted October 14, 2010 ok well then why doesn't it work? Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122319 Share on other sites More sharing options...
PFMaBiSmAd Posted October 14, 2010 Share Posted October 14, 2010 What doesn't work? You haven't shown or stated any actual problems or errors or results (or lack of) in this thread. Based on the information so far, it's likely your query failed due to an error and there is no data at all. Quote Link to comment https://forums.phpfreaks.com/topic/215895-making-arrays-with-database-data/#findComment-1122320 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.