473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pagination

41 New Member
Hello

I have a search page where you select the letter of the alphabet
and the person's information who's name beginning with that letter is displayed.

This function is placed on the web page to search and display the information.

Everything works except one thing.

The problem is if there are 3 pages page one is OK, but when you select next to go to page two the information on page two is no displaying.

Can you see something I missed or have any suggestion?


[PHP]
<?php

function search_display( $org_code, $field, $searching, $find, $let, $stat_type, $contact_field)
{

//db connection and selection
$mysqli = db_connect();
db_select($mysq li, $org_code);

/**-----------------------pagination begins ------------------------**/
//how many rows to show per page
$rowsPerPage = 11;

// by default we show first page
$pageNum = 1;

//if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}

//counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;



//alphabet listing search except all
if(!empty($let) && $let !== "All" )
{
$query = "SELECT p.patient_id, p.last_name, p.first_name, p.id,
c.contact_numbe r
FROM pat p, contact c
WHERE p.id = c.id
AND $field LIKE '$let%'
AND p.pat_status = '$stat_type'
AND p.org_code = '$org_code'
AND p.org_code = c.org_code
AND c.$contact_fiel d = '$contact'
AND p.deleted = 'N'
ORDER BY p.last_name, p.first_name
";
}

//table begins
echo "<table width=\"100%\" height=\"332\" left =\"4\" align = \"\" border=\"0
\" font face =\"arial\">\n ";


//------------------------------looping----------------------------------
$num_service = mysqli_num_rows ($result);
for($i=0; $i < $num_service; $i++)
{
$row = mysqli_fetch_ar ray($result);

list($id, $last_name, $first_name, $id, $contact_number ) = $row;


//zebra stripping
if($i % 2) //alternate row colour
{
$bgcolor="#eeee e0";
}
else
{
$bgcolor="#ebea e0";
}

echo"<tr height=\"10\">< td width=\"20%\" height=\"10\"
bgcolor=\"$bgco lor\"><span class=\"style20 \">
<a href =\"../search_form.php ?\"> $last_name</a></span></td>
<td width=\"18%\" height=\"10\" bgcolor=\"$bgco lor\">
<span class=\"style20 \"> <a href =\"../search_form.php ?
\">$first_na me</a></span></td>
<td width=\"9%\" height=\"10\" bgcolor=\"$bgco lor\"><span
class=\"style20 \">$id</span></td><td width=\"17%\"
height=\"10\" bgcolor=\"$bgco lor\"><span class=\"style20
\">$contact_num ber</span></td>\n";
echo"</tr>\n";

}//end of for loop

/**----------------pagination continue-------------------**/
echo '<br>';

//how many rows we have in database
$result = mysqli_query($m ysqli,$query) or die('Error, query failed');
$numrows = mysqli_num_rows ($result);

//how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

$self = $_SERVER['PHP_SELF'];

/** creating 'previous' and 'next' link plus 'first page' and 'last page' link
print 'previous' link only if not on page one **/

if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = "<a href=\"$self?&p age=$page\">[Prev]</a> ";
$first = "<a href=\"$self?&p age=1\">[First Page]</a> ";
}
else
{
$prev = '[Prev]'; /* we're on page one, don't enable 'previous'
link*/
$first = '[First Page]'; // nor 'first page' link
}

//print 'next' link only if we're not
//on the last page
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = "<a href=\"$self?&p age=$page\">[Next]</a>";
$last = "<a href=\"$self?&p age=$maxPage\">[Last Page]</a>";
}
else
{
$next = '[Next]'; /* we're on the last page, don't
enable 'next' link*/
$last = '[Last Page]'; // nor 'last page' link
}

// print the page navigation link
echo"<center> ". $first . $prev . " <strong>$pageNu m</strong> of
<strong>$maxPag e</strong> pages " . $next . $last."</center>";

$mysqli->close();

}

?>
[/php]
Nov 29 '06 #1
3 2134
theRamones
13 New Member
add 'limit' statement on query
Expand|Select|Wrap|Line Numbers
  1.       $query = "SELECT p.patient_id, p.last_name, p.first_name, p.id, 
  2.                    c.contact_number 
  3.               FROM pat p, contact c 
  4.         WHERE p.id = c.id 
  5.         AND $field LIKE '$let%' 
  6.         AND p.pat_status = '$stat_type' 
  7.         AND p.org_code = '$org_code' 
  8.         AND p.org_code = c.org_code 
  9.         AND c.$contact_field = '$contact' 
  10.         AND p.deleted = 'N' 
  11.         ORDER BY p.last_name, p.first_name 
  12.         limit $offset,11
  13.           ";
Nov 29 '06 #2
assgar
41 New Member
add 'limit' statement on query
$query = "SELECT p.patient_id, p.last_name, p.first_name, p.id,
c.contact_numbe r
FROM pat p, contact c
WHERE p.id = c.id
AND $field LIKE '$let%'
AND p.pat_status = '$stat_type'
AND p.org_code = '$org_code'
AND p.org_code = c.org_code
AND c.$contact_fiel d = '$contact'
AND p.deleted = 'N'
ORDER BY p.last_name, p.first_name
limit $offset,11
";
Thanks for responding and your suggestion. I will try it.

I forgt to include a bit of code found after the select statement.
Won't this bit of code do the same thging?
[php]
$pagingQuery = "LIMIT $offset, $rowsPerPage";
$result = mysqli_query($m ysqli,$query.$p agingQuery) or die('Error, query failed');

[/php]
Nov 29 '06 #3
assgar
41 New Member
Thanks for the suggestions.

I have resolved the problem.
Using the next and other navigation links to pass variables via the URL that is used to retrive data from the database like the "ID" was required.
Dec 1 '06 #4

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

Similar topics

9
3407
by: Sharif T. Karim | last post by:
Anyone know of a up-to-date tutorial for pagination where I can have it like: Prev 1 2 3 4 Next Thanks. -- Sharif T. Karim ....you don't know wrath yet...
1
1760
by: Faree | last post by:
I am workign on a news portal which needs paginaiton as usual.but all the code i got depends on the number of records that will come from database :( .it is working well too. But i need pagination depends on the number of rows or number characters in a variable.for example if there are more than 100 characters in that it should be display with pagination code.could any one comeup with suggestios on this .
1
5816
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
2
2328
by: Chris H | last post by:
I am having a problem with pagination, basically the problem is happening in the "PREV / NUMBERS / NEXT" links, it appears as if the reason is becasue the increment and decrement operators aren't functioning or the $page variable isnt working in that part of the code... Below is the link to the working but broken page.. as well as the main part of my code... Hopefully someone can explain why the operators arent working or maybe see what i...
11
2782
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by going to url's like mywebsite/gallery.php?category=landscape Although the above worked perfectly...
1
7410
by: dhanu | last post by:
How to manage pagination in AJAX? My requirement is similar to GMails inbox feature. Whenever a new mail comes in,the newly arrived mail is at the start of my inbox and last row in that page goes to next page(ie Pagination happens automatically without any page refresh). I have used ajaxdisplay tag library from Source Forge which does pagination but doesnot suffice my requirement.ie Whenever a new record is added then it should also be...
1
6851
by: shalini jain | last post by:
Hi, I want to know how can we do pagination using XSL. There are number of tutorials available on pagination using PHP but nothing with XSL. i am really stuck with my code. Below is the code that i have written for pagination but it displays the link of all the pages at one go i.e. if i have 8 pages showing 10 results per page than it shows links for all 8 pages. Previous 1-10 11-20 21-30 31-40 41-50 51-60 61-70 71-80 Next i want to...
16
2778
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between...
4
3575
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, and the pagination almost works. The first page of the pagination works fine, but when I click on one of the links for one of the next pages, the page is blank. I have seen people mention this problem, and they have been told that a variable is...
2
2593
by: kkshansid | last post by:
this is my search page on which i am getting two parameters from previous page but the problem is that as soon as i click any other next pages my sql query fails as it doesnt get these two parameters kindly help <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title>
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.