Web Development: PHP + a href + POST?

  • Thread starter Thread starter Craig M
  • Start date Start date
C

Craig M

Guest
I am working on search engine for my site, i have that 99% accomplished, but i am having a problem 'sorting' the results.

I would like an option to display 5, 10, 15 etc. results per page, i also have that figured out by using the following:

<a href="<?=$PHP_SELF?>?page=<?=$page?>&order=<?=$order?>&ord=<?=$ord?>&limit=10">10</a>

But i realise this is not the best way of doing it, as this shows the follwing in the URL bar:

http://www.????.com/search.php?page=0&order=id&ord=DESC&limit=10

Which can ofcourse be easily tampered with, any suggestions on better ways of doing this?
Coding is :

<a href="<?=$PHP_SELF?>?
page=<?=$page?>&
order=<?=$order?>&
ord=<?=$ord?>&
limit=10">10</a>

Which Shows:

search.php?page=0&
order=id&
ord=DESC&
limit=10
Works perfectly, thanks Geremy, much appreciated! :D
 
Generally I would make three submit buttons for your search form (method post) with the same id and name, with the value's set to 5 10 and 15 respectively. then just have your php read the button that was pressed and return the correct number of results.

using the example you provided a snippet of code would look something like this:

--- php search page ---
<form action="<?=$PHP_SELF?>" method="POST">
<input type="hidden" id="page" name="page" value="<?=$page?>">
----- repeat for order and ord and add your search box-----
<input type="submit" id="limit" name="limit" value="5">
<input type="submit" id="limit" name="limit" value="10">
<input type="submit" id="limit" name="limit" value="15">
</form>

---- php background---
<?=
// your code above this (remember to use
// $_POST['variable id/name'];
// $_REQUEST['variable id/name'];

$limit = $_REQUEST['limit'];
?>
-----

hope that helps,
-gb
 
Back
Top