Pagination PHP script works on wamp but not on live server - php

I used a code for pagination of the search result. It works fine on the wamp but when i run it on the live server, only page one shows the result and nothing comes up for page two. I think something is wrong with the get functions that I am using. Anybody can guess the error or suggest me a solution. Following is the code used.
$query2 = "SELECT student_information.searcher, student_information.student_number, student_information.birth_date, student_information.first_name, student_information.last_name, student_information.second_name, student_information.gender, student_information.reg_date, student_information.email_add1, student_information.email_add2, student_information.home_phone, student_information.business_phone, student_information.home_address, student_information.city, student_information.province, student_information.postal_code, student_information.country, student_information.native_language, student_information.canadian_citizen, student_information.date_entry, student_information.ref_name, student_information.ref_email, student_information.wdhau, student_information.status, student_information.school_name, student_information.school_number, student_information.school_add, student_information.special_exam_req, student_information.guidance_coun, student_information.phone_school, student_information.fax_school, student_information.email_school, student_information.last_year_att, student_information.min, student_information.oen, student_information.sh_osr, student_information.sp_need, student_information.iep_rec, student_information.academic_fr_rp, student_information.med_note_rec, student_information.osr, student_information.req_date, student_information.date_osr_tran, student_information.date_osr_received, student_information.mse_plar, student_information.mse_plar_date, student_information.literacy_status, student_information.com_inv_hours, student_information.oces_dip FROM student_information,course_information Where student_information.searcher = 'y' ORDER by student_information.first_name ";
$result2 = mysqli_query($connection, $query2);
confirm_query($result2);
$num_rows5 = mysqli_num_rows($result2);
$page_rows = 2;
$total_pages = ceil($num_rows5/$page_rows);
if($total_pages<1){
$total_pages = 1;
}
$pagenum = 1;
if(isset($_GET['pn'])){
$pagenum = $_GET['pn'];
}
if($pagenum<1){
$pagenum = 1;
}else if($pagenum > $total_pages){
$pagenum = $total_pages;
}
$limit = 'LIMIT '.($pagenum-1)*$page_rows.','.$page_rows;
$query = "SELECT student_information.searcher, student_information.student_number, student_information.birth_date, student_information.first_name, student_information.last_name, student_information.second_name, student_information.gender, student_information.reg_date, student_information.email_add1, student_information.email_add2, student_information.home_phone, student_information.business_phone, student_information.home_address, student_information.city, student_information.province, student_information.postal_code, student_information.country, student_information.native_language, student_information.canadian_citizen, student_information.date_entry, student_information.ref_name, student_information.ref_email, student_information.wdhau, student_information.status, student_information.school_name, student_information.school_number, student_information.school_add, student_information.special_exam_req, student_information.guidance_coun, student_information.phone_school, student_information.fax_school, student_information.email_school, student_information.last_year_att, student_information.min, student_information.oen, student_information.sh_osr, student_information.sp_need, student_information.iep_rec, student_information.academic_fr_rp, student_information.med_note_rec, student_information.osr, student_information.req_date, student_information.date_osr_tran, student_information.date_osr_received, student_information.mse_plar, student_information.mse_plar_date, student_information.literacy_status, student_information.com_inv_hours, student_information.oces_dip FROM student_information,course_information Where student_information.searcher = 'y' ORDER by student_information.first_name $limit";
$result = mysqli_query($connection, $query);
confirm_query($result);
$text1 = "Showing <b>2</b> of total <b> $num_rows5</b> results found.";
$text2 = "Page <b>$pagenum</b> of <b>$total_pages</b>";
$paginationctrl = '';
if($total_pages!=1){
if($pagenum>1){
$previous = $pagenum-1;
$paginationctrl .= 'Previous &nbsp ';
for($i=$pagenum-4; $i<$pagenum;$i++){
if($i>0){
$paginationctrl .= ''.$i.' &nbsp ';
}
}
}
$paginationctrl .= ''.$pagenum.'&nbsp ';
for($i=$pagenum+1; $i<=$total_pages;$i++){
$paginationctrl .= ''.$i.' &nbsp ';
if($i>=$pagenum+4){
break;
}
}
if($pagenum!=$total_pages){
$next=$pagenum+1;
$paginationctrl .= '&nbsp &nbsp Next';
}
}
if (!$result) {
// Failure
$_SESSION["message"] = "Admin creation failed. " .mysqli_error($connection);
}
}`

Related

Get method for two variables

For some reason the paging does not work with the search get that I have although it was working fine in pages that don't use the get method. If I search for a term lets say example and I have eleven titles in the database that have in their title the word example 10 the first 10 should appear and then in the second page I should have the eleventh one. However when I try to go to the second page the search get from the first page is lost and I get ?pn=$i
<form class="sea" action="search.php" method="GET">
<input class="searchbar" name="search" type="text" placeholder="Search...">
<button class="searchbutton" name="submit-search" type="submit"><i class="fa fa-search"></i></button>
</form>
<?php
if(isset($_GET['submit-search'])) {
$search = mysqli_real_escape_string($conn, $_GET['search']);
$sql = "SELECT COUNT(*) FROM video_games WHERE video_games_title LIKE '%$search%' OR video_games_genre LIKE '$search'";
$query = mysqli_query($conn, $sql);
$row = mysqli_fetch_row($query);
$rows = $row[0];
$page_rows = 10;
$last = ceil($rows/$page_rows);
if($last < 1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($pagenum < 1) {
$pagenum = 1;
}else if ($pagenum > $last) {
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$sql = "SELECT * FROM video_games WHERE video_games_title LIKE '%$search%' OR video_games_genre LIKE '$search' ORDER BY video_games_id $limit ";
$query = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($query);
$paginationCtrls = '';
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<i class="fas fa-angle-left"></i> ';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= ''.$i.' ';
}
}
}
$paginationCtrls .= ''.$pagenum.' ';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= ''.$i.' ';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'"><i class="fas fa-angle-right"></i> ';
}
}
if ($queryResult > 0) {
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)){
$id = $row["video_games_id"];
$title = $row["video_games_title"];
$genre = $row["video_games_genre"];
$image = $row["video_games_image"];
$description= $row["video_games_description"];
$platform= $row["video_games_platform"];
$price= $row["video_games_price"];
?>
//Putting the data from the database to the html
<?php }//end of while ?>
<div id="pagination_controls"><?php echo $paginationCtrls; ?></div>
If I do some replacements
$paginationCtrls .= ''.$i.' ';
When I press the second page I get the results from the first and the $paginationCtrls also say that I am in the first page eventhough in the url says search=example&submit-search=?pn=2
Why is it not working have I messed with the syntax somwhere?
What can I do to fix it?

Pagination only showing first 10 results instead of x amount of pages with 10 results on each

I have a piece of PHP code that is supposed to loop through all the results and make a new page for every 10 results, however it only shows the first 10 results and no options of next page or page numbers.
Is there a reason for this or have I missed something in the code I have written?
Thanks in advance.
My code is below;
$search_course = "
SELECT title, summary, id
FROM course
WHERE title LIKE '%".$_POST['searchBar']."%'";
$result = $mysqli->query($search_course) or die($mysqli->error);
$search_result = $result->fetch_assoc();
$row = mysqli_fetch_row($result);
//total rows for search
$rows = $row[0];
//number of results per page
$rows_per_page = 10;
//shows last page
$last_page = ceil($rows/$rows_per_page);
if($last_page < 1){
$last_page = 1;
}
$page_number = 1;
if(isset($_GET['pn'])){
$page_number = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
//makes sure page number is between limits of $page_number
if($page_number < 1){
$page_number = 1;
} else if($page_number > $last_page){
$page_number = $last_page;
}
// sets the value of items to view
$limit = 'LIMIT ' .($page_number -1) * $rows_per_page .',' .$rows_per_page;
// query again only grabbing the set number of rows depending on page number
$search_course = "
SELECT title, summary, id
FROM course
WHERE title LIKE '%".$_POST['searchBar']."%'
ORDER BY title DESC $limit";
$result = $mysqli->query($search_course) or die($mysqli->error);
$search_result = $result->fetch_assoc();
//displays to the user the total number of results and the page numbers
$total_number_of_results = "Search Results (<b>$rows</b>)";
$page_user_is_on = "Page <b>$page_number</b> of <b>$last_page</b>";
//set up pagination
$pagination_controls = '';
if($last_page != 1){
if($page_number > 1){
$previous = $page_number - 1;
$pagination_controls .='previous ';
for($i = $page_number - 4; $i < $page_number; $i++)
{
if($i > 0){
$pagination_controls .= ''.$i.' ';
}
}
}
$pagination_controls.=''.$page_number.' &nbsm; ';
//clickable links to the left
for($i = $page_number+1; $i <= $last_page; $i++)
{
$pagination_controls .= ''.$i.' ';
if($i >= $page_number+4){
break;
}
}
if($page_number != $last){
$next = $page_number + 1;
$pagination_controls.=' Next';
}
}
$list = '';
while($row = mysqli_fetch_array($result)){
$title = $row['title'];
$id = $row['id'];
$list.='<p><a href="Selectedcourse.php">'.$title.' </p>';
}
mysqli_close($mysqli);
and the html element;
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel='stylesheet' href='courses.css'>
</head>
<body>
<div class="header">
<h1>Search Results for - <?= $_POST['searchBar'] ?></h1>
</div>
<div>
<h3> <?php echo $page_user_is_on ?> </h3>
<p><?php echo $list; ?></p>
<p><?php echo $search_result['summary']; ?> </p>
</div>
<div id="pagination_controls"><?php echo $pagination_controls; ?></div>
</body>
</html>
This is a good effort to roll your own pagination. It was mostly working. The problem was in your first query here:
$search_result = $result->fetch_assoc();
//This fetches only the first row of results
$row = mysqli_fetch_row($result);
//So this is not the total rows for search
$rows = $row[0];
Here's an updated script using prepared statements, which you really need to use. Unless you love being hacked.
//turn errors on to develop, back off when you go live
error_reporting(E_ALL);
ini_set('display_errors', 1);
//here are my main changes
$search_param = "%" . $_POST['searchBar'] . "%";
$stmt = $mysqli->prepare("SELECT title, summary, id FROM course WHERE title LIKE ?");
$stmt->bind_param("s", $search_param); //learn this
$stmt->execute();
$result = $stmt->get_result();
//This gets the number of rows in a query result
$rows = $result->num_rows;
//number of results per page
$rows_per_page = 10;
//shows last page
$last_page = ceil($rows/$rows_per_page);
if($last_page < 1){
$last_page = 1;
}
if(isset($_GET['pn'])){
$page_number = preg_replace('#[^0-9]#', '', $_GET['pn']);
} else {
$page_number = 1;
}
//makes sure page number is between limits of $page_number
if($page_number < 1){
$page_number = 1;
} else if($page_number > $last_page){
$page_number = $last_page;
}
// sets the value of items to view
$limit = 'LIMIT ' .($page_number -1) * $rows_per_page .',' .$rows_per_page;
//displays to the user the total number of results and the page numbers
$total_number_of_results = "Search Results (<b>$rows</b>)";
$page_user_is_on = "Page <b>$page_number</b> of <b>$last_page</b>";
//query again only grabbing the set number of rows depending on page number
$stmt = $mysqli->prepare("SELECT title, summary, id FROM course WHERE title LIKE ? ".$limit);
$stmt->bind_param("s", $search_param);
$stmt->execute();
$result = $stmt->get_result();
$list = '';
while($row = $result->fetch_assoc()){
$title = $row['title'];
$id = $row['id'];
//I'm assuming you want each link to be different here...
$list.='<p>' . $title . '</p>';
}
mysqli_close($mysqli);
//set up pagination
$pagination_controls = '';
if($last_page != 1){
if($page_number > 1){
$previous = $page_number - 1;
$pagination_controls .='previous ';
for($i = $page_number - 4; $i < $page_number; $i++)
{
if($i > 0){
$pagination_controls .= ''.$i.' ';
}
}
}
$pagination_controls.=''.$page_number.' ';
//clickable links to the left
for($i = $page_number+1; $i <= $last_page; $i++)
{
$pagination_controls .= ''.$i.' ';
if($i >= $page_number+4){
break;
}
}
if($page_number != $last_page){
$next = $page_number + 1;
$pagination_controls.=' Next';
}
}
And finally the HTML section, with only one change:
<div class="header">
<h1>Search Results for - <?= $_POST['searchBar'] ?></h1>
</div>
<div>
<h3> <?php echo $page_user_is_on ?> </h3>
<p><?php echo $list; ?></p>
<p><?php /* echo $search_result['summary']; //Where was this coming from? */?> </p>
</div>
<div id="pagination_controls"><?php echo $pagination_controls; ?></div>

having trouble to integrate search results with pagination

I got the pagination controls and my search results shows 5 results fine. but when I click the second page, all of the search results go away. even though for what I searched, there is more than 5 results in the database. if you would please see the update code in just a second. here is my email bud just in case: raminrahim [at] hotmail [dot] com Please. thanks.
<?php
$paginationCTRLS = '';
$textline1 = '';
$textline2 = '';
$list = '';
if (isset($_GET['search_item'])) {
$search_item = $_GET['search_item'];
if (!empty($search_item)) {
if (strlen($search_item)>=3) {
// This query is just to get total count of rows
$query= "SELECT COUNT(item_id) FROM items"; // $sql
$query_run = mysqli_query($mysqli, $query); // $query
$query_row = mysqli_fetch_row($query_run); // $row
// $rows: here we have the total row count
$rows = $query_row[0]; // pgRows = row[]
// This is the number of results we want displayed per page
$page_rows = 5;
// This tells us the page number of our last page
$last = ceil($rows/$page_rows);
// This makes sure last cannot be less than 1.
if ($last < 1)
{
$last = 1;
}
// Establish the $pagenum variables
$pagenum = 1;
// Get pagenum from URL vars if it present, else it is = 1
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$query = "SELECT `item_id`, `featured_Items` FROM `items` WHERE
`featured_Items` LIKE
'%".mysql_real_escape_string($search_item)."%' $limit";
$query_run = mysqli_query($mysqli, $query);
$query_num_rows = mysqli_num_rows($query_run);
if ($query_num_rows>=1)
{
echo $query_num_rows. ' results found:<br>' . '<br>';
while ($query_row = mysqli_fetch_assoc($query_run))
{
echo $query_row['featured_Items'].'<br>' . '<hr>';
}
}
else
{
echo 'No result found' . '<hr>';
}
} else {
echo 'Not enough keywords to predict your search' . '<hr>';
}
}
$textline1 = "Result:" . '(<b>$rows</br>)';
$textline2 = "Page <b>" . '$pagenum' . "</b> of <b>" . '$last' . "</b>";
if ($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCTRLS .= 'Back ';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i>0){
$paginationCTRLS .= ''.$i.' ';
}
}
}
$paginationCTRLS .= ''.$pagenum.' ';
for ($i = $pagenum+1; $i <= $last; $i++) {
$paginationCTRLS .= ''.$i.' ';
if($i >= $pagenum+4) {
break;
}
}
if ($pagenum != $last) {
$next = $pagenum +1;
$paginationCTRLS .= ' Next ';
}
}
$list = '';
while($row = mysqli_fetch_array($query_run, MYSQLI_ASSOC)) {
$id = $row["item_id"];
$availablesITEMS = $row["featured_Items"];
$list .= '<p>'.$availablesITEMS.'<br>.</p>';
}
}
echo $list . '<br/>';
echo $paginationCTRLS . '<br/>';
?>
You need to set up your query to be able to accept an start point.
Like this:
LIMIT 0, 10
Where the first number corresponds to the starting row your results are going to be obtained from, and the second number equals the amount of results you're going to get from that point on.
So in the sense of your code you'd have to set it up as:
$query = "SELECT `item_id`, `featured_Items` FROM `items` WHERE
`featured_Items` LIKE
'%".mysql_real_escape_string($search_item)."%'
LIMIT ".($pagenum-1)*5.",5";
Let me know if that clears up your doubt.
Edit:
As for enabling pagination through your means, simply change the method in your form to be a GET statement.
<form action="your_page.php" method="get">
Then from your code you can use the
$_GET['search_item']
method instead of POST. This in turn enables you to use those variables on your anchor tags for your pagination.
$paginationCTRLS .= ''.$i.' ';`
Edit2:
You have this piece of code:
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i>0){
$paginationCTRLS .= ''.$i.' ';
}
}
This will always at any point output the same number of pages, which is 5.
Now what you need is something that outputs only the pagination that you really need. So for example setting up this variable:
$pages = ceil($row/$page_rows);
Gives you your total amount of pages, then you can iterate to it:
for($i = 1; $i <= $pages; $i++){
if($i>0){
$paginationCTRLS .= ''.$i.' ';
}
}

Integrating pagination into mysql query

I have the following mysql query and I have added pagination from here:
http://www.tonymarston.net/php-mysql/pagination.html
$DBQuery3 = mysqli_query($dblink, "SELECT * FROM images WHERE project_id = '$FormProjectID'");
if (mysqli_num_rows($DBQuery3) < 1) {
$ProjectContent = '
<p>This project is empty. Upload some files to get started.</p>
';
} else {
//if no page number is set, start at page 1
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
//This code will count how many rows will satisfy the current query.
$DBQuery3b = mysqli_query($dblink, "SELECT count(*) FROM images WHERE project_id = '$FormProjectID'");
$query_data = mysqli_fetch_row($dblink, $DBQuery3b);
$numrows = $query_data[0];
//This code uses the values in $rows_per_page and $numrows in order to identify the number of the last page.
$rows_per_page = 2;
$lastpage = ceil($numrows/$rows_per_page);
//This code checks that the value of $pageno is an integer between 1 and $lastpage.
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
}
if ($pageno < 1) {
$pageno = 1;
}
//This code will construct the LIMIT clause for the sql SELECT statement.
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$DBQuery3c = "SELECT * FROM images WHERE project_id = $FormProjectID $limit";
$DBQuery3d = mysqli_query($dblink, $DBQuery3c);
//set this variable to empty and so we can latwe loop and keep adding images to it
$ProjectContent ='';
while($row = mysqli_fetch_array($DBQuery3d)) {
$DBImageID = $row['image_id'];
$DBProjectID = $row['project_id'];
$DBImageName = $row['image_name'];
$DBImageDescription = $row['image_description'];
$DBDateCreated = $row['date_created'];
$DBLinkToFile = $row['link_to_file'];
$DBLinkToThumb = $row['link_to_thumbnail'];
$DBGivenName = $row['given_name'];
//if the image was given a name by the user, display it
//otherwise display the generated name
if (strlen($DBGivenName) > 1) {
$FileName = $DBGivenName;
} else {
$FileName = $DBImageName;
}
$ProjectContent .= '
<img src="uploads/'.$DBLinkToThumb.'" width="150px" height="150px" alt="'.$FileName.'" title="'.$FileName.'"/>
';
//Finally we must construct the hyperlinks which will allow the user to select other pages. We will start with the links for any previous pages.
if ($pageno == 1) {
$FirstPrev = " FIRST PREV ";
} else {
$First = " <a href='{$_SERVER['PHP_SELF']}?page=project&id=$FormProjectID&pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
$Prev = " <a href='{$_SERVER['PHP_SELF']}?page=project&id=$FormProjectID&pageno=$prevpage'>PREV</a> ";
}
//Next we inform the user of his current position in the sequence of available pages.
$PageNumb = " ( Page $pageno of $lastpage ) ";
//This code will provide the links for any following pages.
if ($pageno == $lastpage) {
$NextLast = " NEXT LAST ";
} else {
$nextpage = $pageno+1;
$Next = " <a href='{$_SERVER['PHP_SELF']}?page=project&id=$FormProjectID&pageno=$nextpage'>NEXT</a> ";
$Last = " <a href='{$_SERVER['PHP_SELF']}?page=project&id=$FormProjectID&pageno=$lastpage'>LAST</a> ";
}
}
}
Then in my html I have:
<div id="projectview">
<?php echo $ProjectContent; ?>
<?php echo $FirstPrev; ?>
<?php echo $First; ?>
<?php echo $Prev; ?>
<?php echo $PageNumb; ?>
<?php echo $NextLast; ?>
<?php echo $Next; ?>
<?php echo $Last; ?>
<div class="clear-div"></div>
</div>
This is outputing for example in this case 2 images, but the pagination links look like this:
FIRST PREV ( Page 1 of 0 ) NEXT LAST
Clicking on the links is not cycling through any other images, it still shows the same 2 images.
I can't figure out what I have done wrong here. I don't understand why it says "1 of 0" when clearly there should be more results.

Pagination not working because of two select statements

$today = date('D, d M, Y');
$sql = "SELECT * FROM table WHERE date = '$today'";
if ($_POST!="") {
$mydate = mysql_real_escape_string($_POST['datepicker']);
if ($mydate != "") {
$sql = "SELECT * FROM table WHERE date = '$mydate'";
}
}
$num_results_per_page = 8;
$num_page_links_per_page = 5;
$pg_param = "";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
pagination($sql, $num_results_per_page, $num_page_links_per_page, $pg_param);
if($pg_error == '')
{
if(mysql_num_rows($pg_result) > 0)
{
while($data = mysql_fetch_assoc($pg_result))
{
echo "";
}
echo "</br>". $pagination_output;
}
else
{
echo "No Data.";
}
}
else
{
echo $pg_error;
}
For the above code the pagination is not working properly. I am thinking that it is because of two select statements. It will be OK if we can combine those two. Any suggestions? How can I combine those two select statements?
Pagination is working correctly for select $today, but not working properly for select $mydate. For example if the user clicks page number two in select $mydate, its again going to select $today.
pagination.php
$pg_error = '';
$pg_result = '';
$pagination_output = '';
$max_pages = '';
$page_id = '';
$page_numbers_per_page = '';
$pg_user_param = '';
function pagination($sql, $num_results_per_page, $num_page_links_per_page, $pg_param)
{
global $pg_error, $pg_result, $max_pages, $page_id, $page_numbers_per_page, $pg_user_param;
$user_sql = $sql;
$page_numbers_per_page = $num_page_links_per_page;
$results_per_page = $num_results_per_page;
$pg_user_param = $pg_param;
$all_results = mysql_query($user_sql);
if($all_results)
{
if(empty($all_results))
{
$total_results = 0;
}
else
{
$total_results = mysql_num_rows($all_results);
}
$max_pages = ceil($total_results / $results_per_page);
if(isset($_GET['page_id']))
{
$page_id = (int) $_GET['page_id'];
if($page_id > $max_pages || empty($page_id))
{
$page_id = 1;
}
}
else
{
$page_id = 1;
}
$page_id_temp = ($page_id - 1) * $results_per_page;
$sql_offset = $page_id_temp;
$user_sql .= " limit $sql_offset, $results_per_page";
$pg_result = mysql_query($user_sql);
Create_Links();
}
else
{
$pg_error = 'Error with the sql query you entered: '.mysql_error();
}
}
function Create_Links()
{
global $pagination_output, $max_pages, $page_id, $page_numbers_per_page, $pg_user_param;
$pg_page_name = htmlspecialchars($_SERVER['PHP_SELF'] );
if($max_pages > 1)
{
if($page_id > 1)
{
$first_link = 'First ';
}
if($page_id < $max_pages)
{
$last_link = 'Last ';
}
$pre_id = $page_id - 1;
if($pre_id != 0)
{
$pre_link = 'Previous ';
}
$next_id = $page_id + 1;
if($next_id <= $max_pages)
{
$next_link = 'Next ';
}
if($page_id >= $page_numbers_per_page)
{
$start_point = ($page_id - $page_numbers_per_page) + 2;
}
else
{
$start_point = 1;
}
$loop_num = ($start_point + $page_numbers_per_page) - 1;
if($loop_num > $max_pages)
{
$loop_num = $max_pages;
}
$pagination_output = '<div class="pagination"> ';
$pagination_output .= $first_link;
$pagination_output .= $pre_link;
for($i = $start_point; $i <= $loop_num; $i++)
{
if($i == $page_id)
{
$pagination_output .= '<a class="current">'.$i.'</a> ';
}
else
{
$pagination_output .= ''.$i.' ';
}
}
$pagination_output .= $next_link;
$pagination_output .= $last_link;
$pagination_output .= '</div><br />';
}
}
?>
If pagination is working for "$today" then it must be the POST input value - are you making sure you're getting a proper date that mysql can understand?
the format should basically match what's in "$today".
I'd imagine that the second click is not POSTing myDate to the next page. The next page then sees nothing in POST and uses today.
To avoid this you could also check for GETs of the datepicker and then pass myDate using GET.
Edit: Clarification on updating the code to use GET
The check on mydate should be changed to something like:
if ($_REQUEST!="") {
$mydate = mysql_real_escape_string($_REQUEST['datepicker']);
if ($mydate != "") {
$sql = "SELECT * FROM table WHERE date = '$mydate'";
}
}
Which means that if the datepicker is from a GET request we still grab it.
Create_Links() should be changed to add "&datepicker=$mydate" (note that you will need to pass in $myDate to ths function.

Categories