472,978 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,978 software developers and data experts.

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 1089
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

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

Similar topics

2
by: Edvard Majakari | last post by:
Hi all ya unit-testing experts there :) Code I'm working on has to parse large and complex files and detect equally complex and large amount of errors before the contents of the file is fed to...
9
by: Martin | last post by:
I am trying to write code that selects a random number in the range 0 to n, where n can be substantially greater than the RAND_MAX on my system which is 32767. I am using VC++ 2003 FWIW. As you...
6
by: Sen-Lung Chen | last post by:
Dear All: I have a question about this below function.The purpose of this function is to generate one number between a and b. -------------------------- int gennum(int a, int b) {...
0
by: D. Dante Lorenso | last post by:
I need to know that original number of rows that WOULD have been returned by a SELECT statement if the LIMIT / OFFSET where not present in the statement. Is there a way to get this data from PG ?...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
5
by: Lee Gillie | last post by:
A surprising, and unexplained behavior was seen from a RELEASE build of a VB application (essentially a console app). It processes thousands of pages of text, and occasionally drops the first...
7
by: itm | last post by:
I have a mail out to send to a group of owners with multiple accounts. I want to limit the number of accounts that print on the first page to 20. I want remaining accounts to print on a second...
8
by: sdlt85 | last post by:
Hi, the program is asking the user for a number ant he base of the number, then it will convert the number to decimal. But is running right only with base 2, 3, 4, 5, 6, 7, 8 but if I try 16 it is...
4
by: ArizonaJohn | last post by:
Hello, The code below works great. The user enters a name into an HTML form, the code looks up a table with that name, and then that table is displayed. I am trying to use pagination with it,...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.