Mikey wrote:

Ross wrote:

I have a query

$query = "SELECT * FROM sheet1 WHERE '$filter' LIKE '$search_field%'"



This prints out a table

while  ($row = @mysql_fetch_array($result, MYSQL_ASSOC)){

// this just fills the empty cells

if ($row['fname']==""){
$row['fname']=" ";
}
if ($row['sname']==""){
$row['sname']=" ";
}
if ($row['organisation']==""){
$row['organisation']=" ";
}

?>

   <td width="71" class="right_line">      <?=$row['fname'];?>     </td>
   <td width="45" class="right_line"><?=$row['sname'];?></td>
<td width="437" class="right_line"><?=$row['organisation'];?></td>
<? if (!$row['email']==""){
?>
<td width="165" class="end_cell"> <div align="left"><a href="view_details.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">details</a> | <a href="edit.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">edit</a> | <a href="delete.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">delete</a> I <a href="mailto:<?=$row['email']; ?>">email</a></div></td>
<?
}
else {
?>
<td width="171" class="end_cell"> <div align="left"><a href="view_details.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">details</a> | <a href="edit.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">edit</a> | <a href="delete.php?id=<?=$row['id'];?>&sname=<?=$row['sname'];?>">delete</a> I <a href="mailto:<?=$row['email']; ?>">empty</a></div></td>
<?
}
?>



</tr>
<?
}
}
?>



but I have the three headings at the top which I want to use to re-order the results alphabetically. So when I click on surname it will re-reorder them aphebetically (z-a) and when I click on it again it will reverse it (a-z)

   <td class="right_line"><strong>Firstname</a></strong></td>
   <td class="right_line"><strong>Surname</strong></td>
   <td class="right_line"><strong>Organisation</strong></td>


hope this is clear.

Ross
Well, your question is a little vague, but to order the mySQL query you should use the ORDER BY clause in your query. You would then have to use a link to re-submit your page with the order by criteria passed in. e.g.

<td class="right_line"><strong><a href="this_page.php?order=f_name&order=desc">Firstname</a></strong></td>


HTH,

Mikey

I should also add the standard caveat: don't use HTML GET or POST data directly in your queries as you place yourself at risk of SQL injection attack.

Mikey

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to