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>

 

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.