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 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 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 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
Archived
This topic is now archived and is closed to further replies.