Variables in Pagination

Hi, I am failry new to php, although have up until now seemed to be doing ok plodding along by myself and trying to solve any problems i have encountered. However i seemed to have been chasing this problem for a while and now think that i simply can’t see the forest for the trees so any advice would be gratefully recieved. I have looked at various forum listings but i still seem to be stuck.

I have a paging script that i modified and changed to get the results and the look that i wanted. The query took two categories from HTML drop down menu’s and returned the results perfectly in to a results page, using POST, of course when i clicked on to the next page the information wasn’t carried across. Now i have the below session at the begining of the search page and the results page. The sessions represent my two search boxes, the first being category and the second location however i am still not carrying the information through the pages. I have tried everything i can think of, i would be grateful for any assistance and advice thank you.

[php] session_start();
session_register (?category?);
session_register (?location?);
$HTTP_SESSION_VARS [?category?] = $category;
$HTTP_SESSION_VARS [?location?] = $location;
?>

Results <?php include 'library/config.php'; include 'library/opendb.php'; $category = $_POST["category"] ; $location = $_POST["location"] ; // how many rows to show per page $rowsPerPage = 10; // 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; $query = "SELECT * FROM vacancies WHERE category = '$category' AND location ='$location'"; $pagingQuery = "LIMIT $offset, $rowsPerPage"; $result = mysql_query($query . $pagingQuery) or die('Error, query failed'); [/php]

First the session_register and mysql functions have been depreciated. You can leave out the session_register lines and the next two will create the session variable and do the assignment. The $HTTP_SESSION_VARS has also been depreciated, you can use $_SESSION instead.

I am not sure what you are asking but I think that when you go load the second page your, drop down boxes are going to their default settings. In order to ‘keep’ the previously selected values you will need to set them with javascript. Something like this:

    var element = document.getElementById('#category');
    element.value = <?php echo "'" . $category "'"; ?>

(if you know jquery this is much easier)
Now your dropdown will be set to the proper value.

Sponsor our Newsletter | Privacy Policy | Terms of Service