Jump to content

[SOLVED] Viewing X amount of results from a MySQL query.


gazfocus

Recommended Posts

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>

 

 

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";

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.