xProteuSx Posted December 5, 2007 Share Posted December 5, 2007 I am trying to write a script where only the first 'x' number of rows of data are displayed. I have been fooling around with this for quite a while, trying for loops, while loops, and do loops. I have gotten some comical results, but things are starting to become more frustrating than funny. I could use a hand ... (and a brain) ... Here's the idea: $result = mysql_query("SELECT * FROM table1 ORDER BY somedate DESC")or die(mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { for ($x=1; $x<=5; $x++) { echo $row[0]; } } } This prints all the rows/entries in the table five times each. What do I do? Quote Link to comment https://forums.phpfreaks.com/topic/80252-solved-display-first-x-rows-of-data/ Share on other sites More sharing options...
asmith Posted December 5, 2007 Share Posted December 5, 2007 why that is $row[0] ? it makes it echo 5 times that , you have to make $row change every time, like : $row[$x] Quote Link to comment https://forums.phpfreaks.com/topic/80252-solved-display-first-x-rows-of-data/#findComment-406728 Share on other sites More sharing options...
sKunKbad Posted December 5, 2007 Share Posted December 5, 2007 SELECT * FROM table1 ORDER BY somedate DESC LIMIT $x Quote Link to comment https://forums.phpfreaks.com/topic/80252-solved-display-first-x-rows-of-data/#findComment-406730 Share on other sites More sharing options...
xProteuSx Posted December 5, 2007 Author Share Posted December 5, 2007 sKunKbaddy, you're the man. I didn't even think to do that using MySQL functions. I guess I should stop trying to think between midnight and 5 am. I seem to resort to these forums mostly during those hours ... Quote Link to comment https://forums.phpfreaks.com/topic/80252-solved-display-first-x-rows-of-data/#findComment-406732 Share on other sites More sharing options...
sKunKbad Posted December 5, 2007 Share Posted December 5, 2007 xProteuSx, I suffer from the same brainlessness late at night. One day you will be the helper, and I will be the helped! Quote Link to comment https://forums.phpfreaks.com/topic/80252-solved-display-first-x-rows-of-data/#findComment-406946 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.