zrweber Posted January 14, 2011 Share Posted January 14, 2011 I'm having some difficulty. I've tried a few things with no luck. :'( Is there a way where I can take only the first 10 results of $row['username']? $query = mysql_query("SELECT * FROM users ORDER BY dirStamp DESC") or die("Sorry there was an error."); $numrows = mysql_num_rows($query); while ($row = mysql_fetch_assoc($query)) { echo $row['username']; echo "</br>"; } Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/224448-taking-first-10-results-from-database/ Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 Use LIMIT: SELECT * FROM users ORDER BY dirStamp DESC LIMIT 10 Quote Link to comment https://forums.phpfreaks.com/topic/224448-taking-first-10-results-from-database/#findComment-1159456 Share on other sites More sharing options...
zrweber Posted January 14, 2011 Author Share Posted January 14, 2011 That's simple! Thank you, that's exactly what I needed. How would I do it if I were to want results 5-10 instead of 1-10? EDIT - Nevermind, I figured it out. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/224448-taking-first-10-results-from-database/#findComment-1159459 Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 Good. Yeah LIMIT can take 2 params. I think the first is where you want to start, and the second is how many you want from there. So results 5-10 would be: LIMIT 5,5 (I think) Quote Link to comment https://forums.phpfreaks.com/topic/224448-taking-first-10-results-from-database/#findComment-1159463 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.