therelelogo Posted December 15, 2010 Share Posted December 15, 2010 Hi, I usually hate when people ask someone to basically write thier codes for them, but this kinda feels like one of those times. Basically i only want 5 returns from my code below, rather than every return that matches my criteria. <?php // Make a MySQL Connection mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM emails WHERE e_to = '{$_SESSION['SESS_LOGON_NAME']}' and e_read = 'NO' ORDER BY ID DESC") or die(mysql_error()); echo "<table border='0'>"; echo "<tr> <th></th> <th></th> <th></th> <th></th> </tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo "[".$row['e_from']; echo "]"; echo ", re: "; echo $row['e_subject']; echo "</td></tr>"; } echo "</table>"; ?> if at all possible could someone help modify my code to do what i want? i would be very grateful. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/221797-how-to-only-return-5-values/ Share on other sites More sharing options...
shlumph Posted December 15, 2010 Share Posted December 15, 2010 Limit your query: SELECT * FROM emails WHERE e_to = '{$_SESSION['SESS_LOGON_NAME']}' and e_read = 'NO' ORDER BY ID DESC LIMIT 5 http://dev.mysql.com/doc/refman/5.1/en/select.html Quote Link to comment https://forums.phpfreaks.com/topic/221797-how-to-only-return-5-values/#findComment-1147838 Share on other sites More sharing options...
therelelogo Posted December 15, 2010 Author Share Posted December 15, 2010 amazing. thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/221797-how-to-only-return-5-values/#findComment-1147845 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.