View unanswered posts | View active topics It is currently Wed Oct 22, 2014 7:59 pm



Reply to topic  [ 5 posts ] 
 Need help on Pagination passing by Search Query 
Author Message
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post Need help on Pagination passing by Search Query
Hi, I am currently facing a problem with my pagination script. I m a beginner user of php and happen search for this pagination script on google and modify it to my uses. I can manage to get the pages split up when i called for the whole results. However the problem i am facing is when i did a search query, the search value was passed by POST method and i was only able to view the 1st page of the results. When i clicked on the next page, it doesnt work anymore but instead showed me the 2nd page of the whole database results. Can anyone here able to assist me? Here's my code :


[PHP]<?php

include "header.php";


$val_d = $_POST['devicesearch'];

if ($_POST['SEARCH'] = 'Device Search')
{
$sql = "SELECT *
FROM device
WHERE device_num LIKE '%$val_d%' or '%$val_d'";

$results1 = mysql_query($sql) or die (mysql_error());

$pagenum = $_GET["pagenum"];
echo "[align=center]";
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$numrows = mysql_num_rows($results1);
$page_rows = 10; //This is the number of results displayed per page
$last = ceil($numrows/$page_rows); //This tells us the page number of our last page
if ($pagenum < 1) //this makes sure the page number isn't below one, or more than our maximum pages
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query

$sql = "SELECT *
FROM device
WHERE device_num LIKE '%$val_d%' or '%$val_d' $max";
$results = mysql_query($sql) or die (mysql_error());

// This is where i output my results
include "FTsearchtable.php";

echo "

[align=center]Page $pagenum of $last

"; // This shows the user what page they are on, and the total number of pages
// First we check if we are on page one.
//If we are then we don't need a link to the previous page or the first page so we do nothing.
//If we aren't then we generate links to the first page, and to the previous page.
if($pagenum>1)
{
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>Previous</a> ";
}
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else
{
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next</a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
}

}
?>
</table>
</body>
</html>
<?php
include "footer.php";
?>[/PHP]


Wed Dec 02, 2009 8:56 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
Hi Xnuiem,

Thanks for help and guidance, the code worked extremely well.

Lastly, I noticed there's a notice sign stating: "Undefined index: pagenum in C:\Program Files\EasyPHP5.3.0www\FTsearchprocessDEV_120209.php on line 26" and " Undefined index: devicesearch in C:\Program Files\EasyPHP5.3.0www\FTsearchprocessDEV_120209.php on line 15 "

any idea how to remove them?


Thu Dec 03, 2009 7:09 pm
Report this post
Profile
Junior Member

Joined: Wed Nov 11, 2009 8:31 pm
Posts: 26
Post 
sure.. thanks again Xnuiem for your advice.
You have been a great help for me. :)


Sun Dec 06, 2009 6:56 pm
Report this post
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.