Hi, I am showing my output using this.
It shows all the records on web page where month is July(07)
But I want it show all the records like: there are 29 records found, I also need 3 records per page, How I will do paging for these. please guide me.

<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$a= $_POST["a"];
mysql_select_db("onm", $con);

$result = mysql_query("SELECT * FROM leaseentry  WHERE LAPeriodEnd like '%-07-%'");


while($row = mysql_fetch_array($result))
  {
  echo "<table cellpadding=2 cellspacing=2 width=100%>
<tr>


</tr>";
  echo "<tr>";
  echo "<th bgcolor=#FFCC00 width=300px>SiteID</th>";
  echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
    echo "</tr>";
  echo "<tr>";
						
  echo "<th bgcolor=#FFCC00>Owner Name</th>";
  echo "<td bgcolor=#FEE9A9>" . $row['OwnerName'] . "</td>";
  
    echo "</tr>";
	
	echo "<tr>";
	echo "<th bgcolor=#FFCC00>Lease Agreement</th>";
	 echo "<td bgcolor=#9BCB5D><a href=".$row['LA'].">".$row['ch']."</a></td>";
	  

	  echo "</tr>";
	  
	
	
	echo "<tr>";
  echo "<th bgcolor=#FFCC00>LA Start Date</th>";
  echo "<td bgcolor=#FEE9A9>" .date("j-F-Y",strtotime($row['LAPeriodStart'])). "</td>";
    echo "</tr>";
	
	echo "<tr>";
  echo "<th bgcolor=#FFCC00>LA End Date</th>";
  echo "<td bgcolor=#FEE9A9>" .date("j-F-Y",strtotime($row['LAPeriodEnd'])). "</td>";
    echo "</tr>";
	
	  echo "<tr>";
	echo "<th bgcolor=#FFCC00>Purchase Order</th>";
	 echo "<td bgcolor=#CB9B5D><a href=".$row['PO'].">".$row['ch']."</a></td>";

	  echo "</tr>";
	  
	
	 echo "<tr>";
  echo "<th bgcolor=#FFCC00>PO Start Date/th>";
  echo "<td bgcolor=#FEE9A9>" .date("j-F-Y",strtotime($row['POStartDate'])). "</td>";
    echo "</tr>";
	
	 echo "<tr>";
  echo "<th bgcolor=#FFCC00>PO End Date</th>";
  echo "<td bgcolor=#FEE9A9>" .date("j-F-Y",strtotime($row['POEndDate']))  . "</td>";
    echo "</tr>";
	

	  echo "<tr>";
	echo "<th bgcolor=#FFCC00>SPA</th>";
	 echo "<td bgcolor=#CB9B5D><a href=".$row['SPA'].">".$row['SPA']."</a></td>";

	  echo "</tr>";
	
	 $b =$row['SiteId']; 
  }
echo "</table>";


mysql_close($con);

?>

Dani AI

Generated

Quick summary and corrections: was right to point you at LIMIT, but remember the order is LIMIT offset,count (offset first). You also need the total row count to show "29 records found" and to compute pages. Since this thread uses the older mysql* functions, update to mysqli or PDO and use prepared statements to avoid injection and because mysql* was removed from modern PHP.

Example (modern, minimal): use a COUNT(*) query to get total rows, compute pages, then fetch only the slice you need.

$perPage = 3;
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;

$mysqli = new mysqli('localhost','dbuser','dbpass','onm');

$month = 7; // numeric month filter
$stmt = $mysqli->prepare("SELECT COUNT(*) FROM leaseentry WHERE MONTH(LAPeriodEnd) = ?");
$stmt->bind_param('i', $month);
$stmt->execute();
$stmt->bind_result($totalRows);
$stmt->fetch();
$stmt->close();

$totalPages = max(1, (int)ceil($totalRows / $perPage));
$page = min($page, $totalPages);
$offset = ($page - 1) * $perPage;

$stmt = $mysqli->prepare(
  "SELECT SiteId, OwnerName, LA, LAPeriodStart, LAPeriodEnd
   FROM leaseentry
   WHERE MONTH(LAPeriodEnd) = ?
   ORDER BY LAPeriodEnd
   LIMIT ?, ?"
);
$stmt->bind_param('iii', $month, $offset, $perPage);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
  // render row (use htmlspecialchars on output)
}
$stmt->close();

Practical tips: always use ORDER BY so pages are deterministic; sanitize and clamp the page GET value; escape HTML output. If LAPeriodEnd is a true DATE column prefer MONTH(...) or a BETWEEN date-range (and proper indexing) instead of string LIKE for performance. For very large tables avoid expensive COUNT(*) on every request — cache totals or estimate when appropriate.

Recommended Answers

All 5 Replies

you should use LIMIT in you query.

SELECT * FROM foo LIMIT $count,$start,;

$count is the count of rows you want to display at a time.
you'll need to pass $start for each pages via URL.

<a href="page.php?start=5">Next page</a>

value of $start will be constructed dynamically depends on currently displayed data. If you currently displayed data is 6-10, then next page should be 11-15.

<?php
if(!$start)$start=0;
$count=3;
SELECT * FROM foo LIMIT $count,$start;
//display
$start = $_GET['start']+$count;
?>
<a href="page.php?start=<?php echo $start; ?>">Next page</a>

code above is to display link to Next page only.

$result = mysql_query("SELECT * FROM leaseentry  WHERE LAPeriodEnd like '%-07-%'");

Where i put $count and $start in my code.
confused.......;)

Please guide me with my example.
Thansk

for example my page name is show.php
then how I can use paging?
Please Please guide me?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.