Raven1313 Posted June 12, 2012 Share Posted June 12, 2012 Hello Everyone, I'm new to PHP and I'm trying to output some data using PHP and MYSQL. When I use my MYSQL Query Browser and I type this: select PREF from hist_index where DATE(PDATE) = DATE(NOW()) AND STKNO = 11; I get the data I need, which is the Price Index of today. But when I echo this out; I get: Resource id #4 I have a project which outputs 10 variable that are available on hist_index table (8 of them under the row where STKNO=11, and the other two are when STKNO=10). I can query the data but I can't seem to find a way to echo them. I read that making an array is the way to go. Instead of "select"ing them one by one, I can select them all and assign them to an array then out put the array. Do I HAVE to use arrays to out put them? Thank in advance Quote Link to comment https://forums.phpfreaks.com/topic/264041-newbie-trying-to-echo-some-data/ Share on other sites More sharing options...
gristoi Posted June 12, 2012 Share Posted June 12, 2012 you are echoing out the resource created from running the query. you need to actually fetch the records: $result = mysql_query("select PREF from hist_index where DATE(PDATE) = DATE(NOW()) AND STKNO = 11"); while($row = mysql_fetch_array($result)){ echo $row['PREF]; } hope it helps Quote Link to comment https://forums.phpfreaks.com/topic/264041-newbie-trying-to-echo-some-data/#findComment-1353121 Share on other sites More sharing options...
DanielHardy Posted June 12, 2012 Share Posted June 12, 2012 echo $row['PREF']; Trailing apostrophe missed from the row declaration in your code. Sorry to be picky but the smallest details can cause hours of head against wall! Quote Link to comment https://forums.phpfreaks.com/topic/264041-newbie-trying-to-echo-some-data/#findComment-1353125 Share on other sites More sharing options...
gristoi Posted June 12, 2012 Share Posted June 12, 2012 happens to the best of us lol Quote Link to comment https://forums.phpfreaks.com/topic/264041-newbie-trying-to-echo-some-data/#findComment-1353126 Share on other sites More sharing options...
Raven1313 Posted June 13, 2012 Author Share Posted June 13, 2012 Thank you Gristoi and Daniel! It works Quote Link to comment https://forums.phpfreaks.com/topic/264041-newbie-trying-to-echo-some-data/#findComment-1353419 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.