pagination - need help on passing of search query.


Posted on 16th Feb 2014 07:03 pm by admin

Hi, i have been trying for days but couldn't get this sorted out. Would like some professional help here.
Basically I got a basic pagination script from google search and the script works absolutely well if i am to display the full results.
However i am using the 'SELECT...WHERE.. LIKE %$val%' and the result works well for the 1st page but not on the 2nd or 3rd page. i had a search form to submit my value. Some help as to where i should proceed is greatly appreciated! Cheers
Here's my coding:

form.php
Code: <form action="FTsearch.php" method="post">
<table border=0 cellspace=1 cellpadding=3 bgcolor;"#353535"
align="center">
<tr>
<td bgcolor="#eeeeff" width="50%">
Device Number
</td>
<td bgcolor="#eeeeff" width="50%">
<INPUT type = "TEXT" name = "devicesearch">
</td>
</tr>
<tr>
<td bgcolor ="eeeeff" colspan=2 align="center">
<INPUT Type="SUBMIT" name="submit" value="Device Search">
</td>
</tr>
</table>
</form>
FTsearch.php
Code: $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 ("Sorry no match found!".mysql_error());

//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$pagenum = $_GET['pagenum'];
echo "<center>";


/* if(!isset($_GET['page'])) {
$pagenum = 1;
} else {
$pagenum = $_GET['page'];
} */

$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 the result display
include "FTsearchtable.php";


echo "

<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> ";
}

}

No comments posted yet

Your Answer:

Login to answer
265 Like 38 Dislike
Previous forums Next forums
Other forums

help with Get_
ok some how this is not working i am not sure what i am doing wrong here but what this does is when

How to search for several parameters from objects in a database?
I have a database with lots of information about objects.
Now I would like to search for 4 or 5 p

User information
Hi All,
By using t-code SUIM we get all the user details,if suppose we donot have permission t

very easy question about SQL info
Hello,
I think that I have a very easy question.
I know how to create a form using php SQL and

Problem in OnClientClick and OnClick sync
Hi,Strange and irritating problem: I have below button declaration in markup of the aspx page:

php file erros / need help please
Hello

Someone decoded a zend file for me.. after uploaded it on ftp i get some errors, i trye

PayPal Redirect Issue
When I have my paypal button set so that is redirects to http://empiremarketing.ca/order.php,it work

Probably Easy, Need help with Check Boxes in PHP Code
hello,

Thanks for looking this over and helping me out. My problem is I have a online store l

strptime() equivalent for php4 ?!
Greetings!

this is my first post, thank you in advance for your replies.

Well, the ti

Edit MySQL Row Using PHP and HTML Form
Hello,

Here's what I'm trying to do. Build a page where a user enters a MySQL row number in.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash