Re: Newbie question, Which way is best?
| From: | Philip Thompson | Date: | Thu, 20 Mar 2008 15:48:14 +0000 |
| Subject: | Re: Newbie question, Which way is best? | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271896@lists.php.net to get a copy of this message | ||
On Mar 19, 2008, at 5:13 PM, George J wrote:
Hi Jason, Hope this helps - my 'display_products.php' script ---------- <form method='post' action='display_products.php'> ... <input type='hidden' name= 'query' value=$query> <input type='submit' Value='Go'></td> ... // pagination routine conditional code... }else{ echo("<a href=\"display_products.php?page=$i\"><img src=$st border=\"0\"I don't know if anyone has answered the question you have asked at least twice... "How do I pass the query to the next page?" Here's how I would approach it. Don't pass the query - all you need is the page number. This code hasn't been tested, but I think you'll get the idea. <?php // thispage.php if (isset ($_POST['submitted'])) {</a> ");} ----------- So calling the script via the form works i.e it passes the neccessary variables to constrct the sql query for the next call. If the user clicks one of the pagination links, that calls itself, all that is passed is the page=$i variable. I need to include the 'SELECT * FROM...' query either as a string or an array of seperate values for the changed query. So, as I see it, the pagination links won't POST the form variables. How do I pass the 'SELECT * FROM mytable WHERE selection=option LIMIT start, range' query to the called script? George
$resultsPerPage = 50; // or whatever value
$page = mysql_real_escape_string ($_POST['page']);
$start = ($page * $resultsPerPage) - $resultsPerPage;
$length = $start + $resultsPerPage;
// Notice how you don't send the query in the POST or GET, just the page number
$sql = "SELECT field FROM table WHERE (field_a = 'someValue') LIMIT $start, $length";
$results = mysql_query ($sql);
}
// Go to next page
$page = $_POST['page'] ? (int) $_POST['page'] + 1 : 1;
?>
...
<form method="post" action="thispage.php">
<input type="submit" value="Go" />
<input type="hidden" name="page" value="<?php echo htmlentities ($page); ?>" />
<input type="hidden" name="submitted" value="1" />
</form>
...
<?php
while ($row = mysql_fetch_array ($results, MYSQL_ASSOC)) {
// Display results} ?> Hopefully that helps a little bit. ~Philip