0

Hello everyone

I have a hard time making this work..

I have some data that i wish to sort by date , and i would like to sort them asc and desc using a jump menu.

I know that within the jump menu i have to call 2 queries to the database (asc and desc) but i came to the conclusion that i dont know how to do that.

Please im begginig for you help :)

2
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by urtrivedi
0
<?php
  $query="select * from table order by date {$_REQUEST['qryorder']}";
.
.
.
.
.
.
?>

<form name=frm action='thispage.php'>
<select name=qryorder onchange='document.frm.submit()'>
<OPTION VALUE='asc'>Ascending
<OPTION VALUE='desc'>Descending
</SELECT>
</form>
.
.
.
.
.

or

<?php
  $query="select * from table order by date {$_REQUEST['qryorder']}";
.
.
.
.
.
?>

<a  href='thispage.php?qryorder=asc' >Ascending order</a>
<a  href='thispage.php?qryorder=desc' >Descending order</a>
.
.
.
..

Edited by urtrivedi: n/a

0

It kinda worked but i have a problem...

It works only the first time the page loads and after the jump menu doesnt change its values.

This is my code , i changed it a bit to match my needs :

// mysql query
$query_kiniseis = "SELECT * FROM kiniseis ORDER BY `date` {$_REQUEST['dateorder']}";

// form java script 
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>

//form it self

<form name="form" id="form">
  <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
    <option value ="date.php?dateorder=asc">ASC</option>
    <option value ="date.php?dateorder=desc">DESC</option>
    </select>
</form>

When i change the values from the browser ( dateorder=asc dateorder=desc ) the data are sorting as expected but the jump menu is not functional.
Im using dreamweaver.

Thanks in advance

Edited by freiheit: n/a

0

I dont know what you are asking for but I guess that you want to set selection box to the value selected by user. you may achive it using following code

<option value ="date.php?dateorder=asc" 
<?php echo ($_REQUEST['dateorder']=='asc')?"selected":"";?> >ASC</option>    
<option value ="date.php?dateorder=desc" 
 <?php echo ($_REQUEST['dateorder']=='desc')?"selected":"";?> >DESC</option>

Edited by urtrivedi: n/a

0

One last thing for this to be perfect ,

I would like when im changing order , not the data to be displayed from the begining but in the current page.

Say for example im in page 10th of the data with the desc ordering , i would like to change to asc , but the page to keep showing me the 10th page.

My exact code is this

<form method="get" name="form" id="form">
    <select name="jumpMenu" id="jumpMenu" onchange="MM_jumpMenu('parent',this,0)">
      <option value="Hmerisies_Kiniseis.php?dateorder=asc"
          <?php echo ($_REQUEST['dateorder']=='asc')?"selected":"";?>
          >OLD => NEW</option>
      <option value="Hmerisies_Kiniseis.php?dateorder=desc"
          <?php echo ($_REQUEST['dateorder']=='desc')?"selected":"";?>
          >NEW => OLD</option>
      </select>
  </form>

I have a feeling i must use something like %s?page=%d%s but i dont know where

0

You need to learn about "limit" clause of mysql

in user form

.
.
.

<input type=hidden name=page value=<?php echo $_REQUEST['page'];?> >
</form>

in query

$recperpage=10;
if ($_REQEUST['page']=="")
   $_REQEUST['page']=0;
$startfrom=$_REQEUST['page']*$recperpage;

$query=" SELECT * FROM kiniseis 
 order by date {$_REQUEST['dateorder']} 
 limit {$startfrom},{$recperpage} ";

Edited by urtrivedi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.