473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 1097
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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.