turpentyne Posted September 4, 2010 Share Posted September 4, 2010 I have a search page that then submits to a php page that queries the database. I've been struggling to figure out how to paginate it, but I think I've narrowed down the problem. I didn't realize $_POST results didn't pass through when people clicked the pagination links at the bottom. I verified this by replacing the LIKE variable with a specific word and it worked. I'm trying to learn how to set up sessions, thinking this might solve my problem. Doesn't seem to be working. Can I get some suggestions on how to do this? What's happening now is that it's pulling a random 8 pages that have nothing to do with the original query. I start my entire page with: <?php session_start(); $_SESSION['leafshape'] = $_post['select1']; $_SESSION['leafcolor'] = $_post['select2']; $_SESSION['leafvein'] = $_post['select3']; $_SESSION['leafmargin'] = $_post['select4']; $leafshape = $_SESSION['leafshape']; $leafcolor = $_SESSION['leafcolor']; $leafvein = $_SESSION['leafvein']; $leafmargin = $_SESSION['leafmargin']; and I'm setting up the queries like this: $query = "SELECT COUNT(*) as num FROM descriptors JOIN plantae ON (descriptors.plant_id = plantae.plant_name) WHERE descriptors.leaf_shape LIKE '{$_SESSION['leafshape']}' AND descriptors.leaf_venation LIKE '{$_SESSION['leafvein']}' AND descriptors.leaf_margin LIKE '{$_SESSION['leafmargin']}'"; I also tried replacing the '{$_SESSION['leafshape']}' in the query with the assigned variable $leafshape Quote Link to comment Share on other sites More sharing options...
Crashthatch Posted September 4, 2010 Share Posted September 4, 2010 1) Should it be $_POST rather than $_post ? 2) If you have that posted part at the top of both page 1 and page 2 you'll get this problem: At the very start of your script (on page 2) the $_SESSION['leafshape'] variable will contain the correct value which was set on page 1 (you can check this by putting in var_dump( $_SESSION) immediately after the session_start()), but you're immediately overwriting it with the (now empty) $_post['select1']. You need to check if $_post['select1'] is empty, and if it is then don't include the line: $_SESSION['leafshape'] = $_post['select1']; Quote Link to comment Share on other sites More sharing options...
turpentyne Posted September 4, 2010 Author Share Posted September 4, 2010 Hmm. I think I've just run into a whole different problem now. I didn't notice I hadn't capitalized $_POST. Once I did, now the query only pulls one record, and has no pagination links at the bottom. uh-oh. (it should pull 6 records, at 2 per page) The Session script is not at the top of page 1, because that's just a simple html form that sends to the second page made with php. I dropped in the var_dump( $_SESSION) and it shows the variable is filled. So maybe that part is ok? Quote Link to comment Share on other sites More sharing options...
sasa Posted September 4, 2010 Share Posted September 4, 2010 <?php session_start(); if(isset($_POST)){ $_SESSION['leafshape'] = $_POST['select1']; $_SESSION['leafcolor'] = $_POST['select2']; $_SESSION['leafvein'] = $_POST['select3']; $_SESSION['leafmargin'] = $_POST['select4']; } $leafshape = $_SESSION['leafshape']; $leafcolor = $_SESSION['leafcolor']; $leafvein = $_SESSION['leafvein']; $leafmargin = $_SESSION['leafmargin']; Quote Link to comment Share on other sites More sharing options...
turpentyne Posted September 4, 2010 Author Share Posted September 4, 2010 ah... makes sense to add isset. unfortunately I still have the same problem. only one record, and no pagination. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.