yuckysocks Posted March 14, 2009 Share Posted March 14, 2009 Hello. I have a query, and I want the results eventually to be variables that I serve to a JS library to make graphs. I have this currently: $result = mysql_query("SELECT * FROM weatherdata ORDER BY id DESC LIMIT 10"); $row = mysql_fetch_array($result) or die(mysql_error()); $row2 = array_reverse($row); foreach($row2 as $a){ echo $a."<br />"; } The table is 5 fields (including the key ID). The returned output is only the most recent entry, twice! 18<br />18<br /> 13<br />13<br /> 51<br />51<br /> Mostly Cloudy<br />Mostly Cloudy<br /> Last Updated on Mar 14, 4:54 pm EDT<br />Last Updated on Mar 14, 4:54 pm EDT<br /> With the actual DB entry looking like this: ID = 18 Wind = 13 temp = 51 weatherstr = Mostly Cloudy date = Last updated on Mar 14, 4:54 pm EDT I don't know why it only shows the most recent entry (DB has >50 entires so far, it's populated hourly), nor why it's shown twice. What I'm looking for, eventually, is to query the 10 most recent entries, and set the "temp" result for each as a variable ($a, $b, $c...) and then feed those variables to a JS library to make a graph. Any suggestions would be helpful! Quote Link to comment https://forums.phpfreaks.com/topic/149432-how-do-i-turn-a-sql-query-into-variables/ Share on other sites More sharing options...
MadTechie Posted March 14, 2009 Share Posted March 14, 2009 you are only fetching once thus getting one results! its showing twice because your using fetch_array that has numeric and assocated try a loop ie <?php $result = mysql_query("SELECT * FROM weatherdata ORDER BY id DESC LIMIT 10"); while($row = mysql_fetch_array($result)) { echo $row['ID']." - ".$row['Wind ']."<br />"; //etc } ?> Quote Link to comment https://forums.phpfreaks.com/topic/149432-how-do-i-turn-a-sql-query-into-variables/#findComment-784898 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.