I have a search box named $query and few option lists named $selection, $sortField, and $sortType in a form.
when I type something in $query and made my selections, I press submit button.
Then I have a mysql query to find 'like' $query and it will display records in a pagination style.
My problem is that it displays records on page 1 but when clicked next button or page 2, all my variables are blank.
I see that the variables don't pass to next page. So I included session_start and session_register but still my variables won't pass. Any help will be appriciated.
ON THE VERY TOP OF MY PAGE:
<? session_start(); // to keep variables saved
// header("Cache-control: private"); is used to hit BACK button without refresh in MS 6
header("Cache-control: private"); ?>
AFTER SUBMIT BUTTON:
// Get the user's input from the form
$query = $_POST['query'];
// Register session key with the value
$_SESSION['query'] = $query;
IN THE MYSQL CONNECTION SECTION I HAVE:
$selection = $selection;
$sortField = $sortField;
$sortType = $sortType;
$sql = "select * from products WHERE $selection like \"%$query%\" order by $sortField $sortType LIMIT $limitvalue, $user_view_limit";
$result = mysql_query($sql) or die;// ("Error in query: $query. " . mysql_error());
/ the query to get the total number without the limit /
$sqlcount = "select count(*) from products where $selection like \"%$query%\"";
AND IN PAGINATION SECTION I HAVE:
<?
/ if theres more than one page needed, print out the page #s
In this example, products.php is the page that the link will be printed out with.
To use a different page, simply change this value in your function call /
if ($user_view_limit < $totalrows) {
make_user_page_nums($totalrows, $print_query, "$PHP_SELF");
}
/ THE ACTUAL make_user_page_nums FUNCTION /
/ ----------------------------------------/
function make_user_page_nums($totalrows, $print_query, $page_name) {
//if (isset($HTTP_GET_VARS['id'])) $id = $HTTP_GET_VARS['id'];
//if (isset($HTTP_POST_VARS['id'])) $id = $HTTP_POST_VARS['id'];
//if (isset($HTTP_POST_VARS['title'])) $title = $HTTP_POST_VARS['title'];
//if (isset($HTTP_POST_VARS['title'])) $title = $HTTP_POST_VARS['title'];
// global $print_query;
global $user_view_limit;
global $page;
global $limitvalue;
echo "<font size='4'>";
echo "Pages: ";
echo "</font>";
/ PREV LINK: print a Prev link, if the page number is not 1 /
if($page != 1) {
$pageprev = $page - 1;
echo "<font size='4'>";
echo "<a href=\"".$page_name.$print_query."page=".$pageprev."\"><Prev</a> ";
echo "</font>";
}
/ get the total number of pages that are needed /
$numofpages = $totalrows/$user_view_limit;
/ loop through the page numbers and print them out /
for($i= 0; $i < $numofpages; $i++) {
/ if the page number in the loop is not the same as the page we're on, make it a link /
$real_page = $i + 1;
if ($real_page!=$page){
echo "<font size='4'>";
echo " <a href=\"".$page_name.$print_query."page=".$real_page."\">".$real_page."</a> ";
echo "</font>";
/ otherwise, if the loop page number is the same as the page we're on, do not make it
a link, but rather just print it out /
} else {
echo "<font size='5'>";
echo "<b>".$real_page."</b>";
echo "</font>";
}
}
/ NEXT LINK -
If the totalrows - $user_view_limit $page is > 0 (meaning there is a remainder), print the Next button. /
if(($totalrows-($user_view_limit$page)) > 0){
$pagenext = $page + 1;
echo "<font size='4'>";
echo " <a href=\"".$page_name.$print_query."page=".$pagenext."\">Next ></a> ";
echo "</font>";
}
}
/ END OF PAGE NUMBERING SNIPPET CODE /
/ ----------------------------------------/
?>
please give me any hints or tips or watever on how to get my sesseions to page 2
Thanks!
I build this code through http://www.phpfreaks.com/tutorials/43/1.php