|
Posted by J.O. Aho on 11/22/06 13:03
alex.kemsley@hottubs2buy.co.uk wrote:
> Dear All,
>
> Can you tell me if its possible to ORDER BY 'searchtype' where the html
> for passes a value such as 'table.column ACS' and the php calls it from
> the $_GET['searchtype']
>
> If not is there another way of doing this.
It's possible to set ordering ways with a form,
$query="SELECT * FROM table";
if(!empty($_REQUEST['searchtype']))
$query.=" ORDER BY ".$_REQUEST['searchtype'];
That should add what you need part if the searchtype was submitted, if not
then default order is given (no ordering has been set).
Another way is to limit the ordering ways is to have a "drop down menu" in the
form page where you list the ways
<select name="searchtype">
<option value="0">Default</option>
<option value="1">Column 1</option>
<option value="2">Column 2</option>
<option value="3">Column 3</option>
<option value="4">Column 4</option>
</select>
and in the php script that does the database query
$query="SELECT * FROM table";
switch($_REQUEST['searchtype']) {
case 1:
$query.=" ORDER BY column1 ASC";
break;
case 2:
$query.=" ORDER BY column2";
break;
case 3:
$query.=" ORDER BY column3 ASC";
break;
case 4:
$query.=" ORDER BY column4";
break;
}
This way no one can order the results in a way you don't want them to.
//Aho
Navigation:
[Reply to this message]
|