473,387 Members | 1,516 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,387 software developers and data experts.

Pagination

41
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($mysqli, $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_number
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_field = '$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_array($result);

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


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

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

}//end of for loop

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

//how many rows we have in database
$result = mysqli_query($mysqli,$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?&page=$page\">[Prev]</a> ";
$first = "<a href=\"$self?&page=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?&page=$page\">[Next]</a>";
$last = "<a href=\"$self?&page=$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>$pageNum</strong> of
<strong>$maxPage</strong> pages " . $next . $last."</center>";

$mysqli->close();

}

?>
[/php]
Nov 29 '06 #1
3 2112
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
add 'limit' statement on query
$query = "SELECT p.patient_id, p.last_name, p.first_name, p.id,
c.contact_number
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_field = '$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($mysqli,$query.$pagingQuery) or die('Error, query failed');

[/php]
Nov 29 '06 #3
assgar
41
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
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
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...
1
by: Kruq | last post by:
Is it possible to use pagination with DataList? Can't find it.. :( Kruq
2
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...
11
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. ...
1
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...
1
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...
16
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) ...
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,...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.