-1

I have a PHP-based sorting method with a drop-down menu to sort rows. It works. I have another sorting links to sort id and title. It also works. But together they do not work.

When I sort (say by title) using links, the result gets sorted by title, then if I sort rows using my drop-down menu, rows get sorted, but the result gets set back to the default of id sort.

My sorting code for ID and title:

    if ($orderby == 'title' && $sortby == 'asc')
{echo " <li id='scurrent'><a href='?rpp=$rowsperpage&order=title&sort=asc'>title-asc:</a></li> ";}
else {echo " <li><a href='?rpp=$rowsperpage&order=title&sort=asc'>title-asc:</a></li> ";}   

if ($orderby == 'title' && $sortby == 'desc')
{echo " <li id='scurrent'><a href='?rpp=$rowsperpage&order=title&sort=desc'>title-desc:</a></li> ";}
else {echo " <li><a href='?rpp=$rowsperpage&order=title&sort=desc'>title-desc:</a></li> ";} 

if ($orderby == 'id' && $sortby == 'asc')
{echo " <li id='scurrent'><a href='?rpp=$rowsperpage&order=id&sort=asc'>id-asc:</a></li> ";}
else {echo " <li><a href='?rpp=$rowsperpage&order=id&sort=asc'>id-asc:</a></li> ";}     

if ($orderby == 'id' && $sortby == 'desc')
{echo " <li id='scurrent'><a href='?rpp=$rowsperpage&order=id&sort=desc'>id-desc:</a></li> ";}
else {echo " <li><a href='?rpp=$rowsperpage&order=id&sort=desc'>id-desc:</a></li> ";} 
?>

My sorting codes for rows:

<form action="is-test.php" method="get">
<select name="rpp" onchange="this.form.submit()">    
<option value="10" <?php if ($rowsperpage == 10) echo 'selected="selected"' ?>>10</option>
<option value="20" <?php if ($rowsperpage == 20) echo 'selected="selected"' ?>>20</option>
<option value="30" <?php if ($rowsperpage == 30) echo 'selected="selected"' ?>>30</option>   
</select>
</form>    

This method passes only rows per page (rpp) into url. I want it to pass order, sort, and rpp. Is there a way to pass these multiple values in form fields.

phsource
  • 2,326
  • 21
  • 32

1 Answers1

0

Are you allowing the user to change ordering as well?

If so, add another input for it of some input type.

If not, add a hidden input <input type="hidden" name="sort" value="asc"> or simply have the options manipulate the URL and not submit a form. Another Stackoverflow solution has something that works really similarly to this: https://stackoverflow.com/a/1091005/319066

Community
  • 1
  • 1
phsource
  • 2,326
  • 21
  • 32
  • thanks for replay i have done likr this , this way i am able to pass two more values in url, can i pass value as variable. –  Jun 01 '12 at 06:03
  • i tried like this and url is like this is-test.php?rpp=10&order=+id&sort=+asc, how can i remove this + sign –  Jun 01 '12 at 06:08
  • You just need to remove the space before the ` – phsource Jun 01 '12 at 06:14
  • thanks a lot man, you are awesome, now everything is working as it should. –  Jun 01 '12 at 06:19