gazfocus Posted December 17, 2008 Share Posted December 17, 2008 I have a website where one page calls records from a table in my database. Is there a way to get just for example the first 5 records? Here's my code: <html> <head> <SCRIPT TYPE="text/javascript"> </SCRIPT> <link href="/joomla/templates/at_flexmen/css/template_css.css" rel="stylesheet" type="text/css"> </head> <body> <?php ////////////////////////////////////////// //// MySQL Database Connection /////////// ////////////////////////////////////////// $host = "xxxxx"; $user = "xxxxx"; $db_name= "xxxxx"; $pass= "xxxxx"; $conn = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db_name, $conn) or die(mysql_error()); $sql = "SELECT eventTime, DAYNAME(eventDate) as day, DATE_FORMAT(eventDate,'%D %M %Y') as eDate , venue, title, description FROM kirkbydiarydates WHERE eventDate >= curdate() ORDER by eventDate ASC"; if ($result = mysql_query($sql,$conn)) { if (mysql_num_rows($result)) { while ($newArray = mysql_fetch_array($result)) { $eventTime = $newArray['eventTime']; $eventDay = $newArray['day']; $eventDate = $newArray['eDate']; $venue = $newArray['venue']; $title = $newArray['title']; $description = $newArray['description']; echo "<table width=\"100%\" border=\"0\"> <tr> <td><p style=\"font-size:12px; color:#b53a04; background-color:#e3e8eb\"><b>$title</b></p><p style=\"font-size:12px\"></td> </tr> <tr> <td>$eventDay $eventDate</td> </tr> </table>"; } } } ?> <br /> <a href="http://test.kirkbyjubilee.org.uk/index.php?option=com_content&view=article&id=18&Itemid=10">More Details</a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/137391-solved-viewing-x-amount-of-results-from-a-mysql-query/ Share on other sites More sharing options...
rhodesa Posted December 17, 2008 Share Posted December 17, 2008 add a 'LIMIT 5' to the end of the SQL statement: $sql = "SELECT eventTime, DAYNAME(eventDate) as day, DATE_FORMAT(eventDate,'%D %M %Y') as eDate , venue, title, description FROM kirkbydiarydates WHERE eventDate >= curdate() ORDER by eventDate ASC LIMIT 5"; Link to comment https://forums.phpfreaks.com/topic/137391-solved-viewing-x-amount-of-results-from-a-mysql-query/#findComment-717920 Share on other sites More sharing options...
gazfocus Posted December 17, 2008 Author Share Posted December 17, 2008 add a 'LIMIT 5' to the end of the SQL statement: $sql = "SELECT eventTime, DAYNAME(eventDate) as day, DATE_FORMAT(eventDate,'%D %M %Y') as eDate , venue, title, description FROM kirkbydiarydates WHERE eventDate >= curdate() ORDER by eventDate ASC LIMIT 5"; Thanks, that did the trick Link to comment https://forums.phpfreaks.com/topic/137391-solved-viewing-x-amount-of-results-from-a-mysql-query/#findComment-717925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.