Re: re-order a sql result

From: Date: Mon, 18 Jul 2005 11:01:43 +0000
Subject: Re: re-order a sql result
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-218862@lists.php.net to get a copy of this message
""Ross"" <ross@aztechost.com> wrote in message news:D9.31.61486.D7A8BD24@pb1.pair.com... > I have a query > > $query = "SELECT * FROM sheet1 WHERE '$filter' LIKE > '$search_field%'" > Simply requery the database for each search. For example, this orders the results by surname from a-z $query = "SELECT * FROM sheet1 WHERE '$filter' LIKE '$search_field%' ORDER BY surname ASC"; > > > This prints out a table > > while ($row = @mysql_fetch_array($result, MYSQL_ASSOC)){ > > // this just fills the empty cells > > if ($row['fname']==""){ > $row['fname']="&nbsp;"; > } > if ($row['sname']==""){ > $row['sname']="&nbsp;"; > } > if ($row['organisation']==""){ > $row['organisation']="&nbsp;"; > } > > ?> > > <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'];?>">detail s</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'];?>">detail s</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

« previous php.general (#218862) next »