468,242 Members | 1,654 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,242 developers. It's quick & easy.

how to limint the number of result that occur in one page?

i have create a search engin for searching a database. Then i want to limit the result that appear in one page. Let say 10 result in one page. How can i do it with php?
Oct 20 '06 #1
2 973
ronverdonk
4,258 Expert 4TB
Best is to look at the numerous PHP pagination scripts that you can use freely. For example: http://www.tkap.org/paginator/index.php

Ronald :cool:
Oct 20 '06 #2
According to the webpage u give me last time, i had write acode abut the pagination. But now i have the problem at this line

"while(list($NameItem) = mysql_fetch_array($result2)) { "

If i want to put all the selected field instead of only NameItem as what i had i done in the query, how should i do?

<?
//required file for database connection
require("config.php");
$query = "SELECT *FROM listofitem ";
$result = mysql_query($query);

$num_record = mysql_num_rows($result);

$display = 10;

if (empty($startrow)) {
$startrow=0;
}

$query2 = "SELECT *FROM listofitem LIMIT $startrow, $display";
$result2 = mysql_query($query2);

print("<table border=0><tr>");

$counter = 0;

while(list($NameItem) = mysql_fetch_array($result2)) {

if ($counter == 3) {
print("</tr><tr>");

$counter = 0;
}

print("<td bgcolor=#004A80 width=200 height=200 align=center><font color=#FFFFFF>$NameItem</font><br><font color=#FFFFFF>");


$counter = $counter + 1;
}

if ($startrow != 0) {
$prevrow = $startrow - $display;
print("<a href=\"$PHP_SELF?startrow=$prevrow\">Previous</a> ");
}

$pages = intval($num_record / $display);

if ($num_record % $display) {

$pages++;
}

if ($pages > 1) {
for ($i=1; $i <= $pages; $i++) { // Begin loop
$nextrow = $display * ($i - 1);
print("<a href=\"$PHP_SELF?startrow=$nextrow\">$i</a> ");
}
}

if (!(($startrow / $display) == $pages) && $pages != 1) {

$nextrow = $startrow + $display;
print("<a href=\"$PHP_SELF?startrow=$nextrow\">Next</a>");
}

if ($num_record < 1) {
print("<table border=0 width=795><tr><td>$XX</td></tr></table>");
}
?>
Oct 27 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Sen-Lung Chen | last post: by
122 posts views Thread by Einar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.