Jump to content

Pagination with _POST, could you please help?


Valentina

Recommended Posts

Hello,

I believe this question was probably answered to death, and I looked for old posts, but I couldn't find anything to solve my problem... Could somebody please help me?

I wrote a search script that needs pagination. The script uses the _POST method to deal with the variables in the form.

Being a beginner, it took me a while to realize that _POST does not carry the variables to the next page, but I cannot use _GET - there are too many variables that need to be passed to the next page.

I tried SESSION also, but I either don't use it right, or it's simply not working... I cannot tell.

What would be the best way to deal with this problem?

I can post parts of the script if you need me to, I just am not sure what exactly would be needed...

Thank you so much for your help!

 

 

 

 

Valentina

Not really sure what your asking for, can you please clarify. By the way when using session. You need session_start() at the beginning of each page you want to be part of the session. your variables get stored like this

 

 

$_SESSION['Your-Variable-Name-Here']

Lisa, I have no idea how to do that.

If you could offer some code to help me, I would appreciate it very much.

 

 

vicodin, I am trying to create links for pages. I want to query the MySql database, get a bunch of results and display only 10 per page. I have no problem doing all these using GET, but it's not working with POST. I need to use POST.

 

This is my code when trying with SESSION:

 

<?php
session_start();
?>
<html>
<head>


...... stuff here, form.......



if (!isset($_SESSION['hybridizer']) || !isset($_SESSION['seedparent']) || !isset($_SESSION['color[]']) || !isset($_SESSION['flowerform[]']) 
  || !isset($_SESSION['orgcountry']) || !isset($_SESSION['year'])) 
    {
     $_SESSION['hybridizer']=$_POST['hybridizer'];
     $_SESSION['seedparent']=$_POST['seedparent'];
     $_SESSION['color[]']=$_POST['color[]'];
 $_SESSION['flowerform[]']=$_POST['flowerform[]'];
 $_SESSION['orgcountry']=$_POST['orgcountry'];
 $_SESSION['year']=$_POST['year'];	 
     }

$hybridizer = htmlentities($_SESSION['hybridizer']);
$cleanhybridizer = trim($hybridizer); 

$seedparent = htmlentities($_SESSION['seedparent']);
$cleanseedparent = trim($seedparent); 

$color = $_SESSION['color[]'];
$color_1 = $color[0]; 
$color_2 = $color[1]; 
$color_3 = $color[2]; 
$color_4 = $color[3]; 
$color_5 = $color[4]; 
$color_6 = $color[5]; 
$color_7 = $color[6]; 
$color_8 = $color[7]; 
$color_9 = $color[8]; 

$flowerform = $_SESSION['flowerform[]'];
$flowerform_1 = $flowerform[0]; 
$flowerform_2 = $flowerform[1]; 
$flowerform_3 = $flowerform[2]; 

$orgcountry = htmlentities($_SESSION['orgcountry']);
$cleanorgcountry = trim($orgcountry); 

$year = htmlentities($_SESSION['year']);
$cleanyear = trim($year); 


........ then all the script stuff.....

 

 

Am I doing something wrong here?

How exactly am I supposed to write the links to the next page? Would it be something similar to writing them for GET, but just use SESSION[] instead? Or there is no need to write everything in the link anymore... I am really not sure what I'm doing...

 

I appreciate your help!

 

 

 

 

Valentina

 

 

 

Post works the same way as get. It just doesnt go in the URL and is only passed to the next page. After the next page its gone. So intead of $_GET['Your-Var'] use $_POST['Your-Var'] and make sure in your form you change the method to post.

vicodin, I am not sure I understand what you're saying....

I tried using POST like this:

 

$hybridizer = htmlentities($_POST['hybridizer']);
$cleanhybridizer = trim($hybridizer); 

$seedparent = htmlentities($_POST['seedparent']);
$cleanseedparent = trim($seedparent); 

$color = $_POST["color"];

$color_1 = $color[0]; 
$color_2 = $color[1]; 
$color_3 = $color[2]; 
$color_4 = $color[3]; 
$color_5 = $color[4]; 
$color_6 = $color[5]; 
$color_7 = $color[6]; 
$color_8 = $color[7]; 
$color_9 = $color[8]; 

$flowerform = $_POST["flowerform"];  

$flowerform_1 = $flowerform[0]; 
$flowerform_2 = $flowerform[1]; 
$flowerform_3 = $flowerform[2]; 

$orgcountry = htmlentities($_POST['orgcountry']) ;
$cleanorgcountry = trim($orgcountry); 

$year = htmlentities($_POST['year']) ;
$cleanyear = trim($year); 

 

 

And then later, for pages, I have this:

 

echo "<a href='{$_SERVER['PHP_SELF']}?page_number=$next&hybridizer=$hybridizer&seedparent=$seedparent&color[] .......... all the rest of them ........    </a>

 

When you click on the next page, there are no variables. They are lost.

 

I tried doing all these using GET in the form. It works, but it doesn't carry all the variables.

 

 

 

 

Valentina

 

Well, these variables are coming from a form that uses method POST.

 

As I said, I tried SESSION (I posted the code earlier) but I am not sure if I'm doing something wrong and I have no idea what I'm supposed to do next with those variables, to pass them to the next page.

 

 

 

Valentina

Post your form please... As long as the very first thing on the page is

<?php
session_start();
?>

And you are using it like this:

<?php
$flowerform = $_SESSION['flowerform'];
?>

 

Then there is no reason for it not to work besides sessions being turned off in you php.ini ...

 

Well, I discovered what I was doing wrong... I wasn't registering the arrays in the form. I was writing the code wrong.

Anyway, I got that fixed, but this SESSION method doesn't work for what my script is trying to do...

My form has multiple search options... lots of checkboxes and text boxes...

When I use SESSION, it works to do a search for the first time (I don't even know if the pagination works) but if I want to do another search, choosing different boxes to check, the script obviously remembers the first choices too.

 

I am not sure what I should do....

 

 

 

 

Valentina

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.