Jump to content


Sort by...


5 replies to this topic

#1 Squid

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:Netherlands
  • Interests:Webdesign, php coding, visual basic programming

Posted 08 November 2005 - 12:44 PM

Hey people, I've been wondering for a while now on how to sort a list ordered by name. If anyone could point me to a good tutorial for example on how to do that, I'd be happy. Since I haven't found what I've been looking for myself yet.

Here's the headers of the table, from which the data from the database is selected and displayed:

<?

echo (" 

<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" marginheight=\"0\" marginwidth=\"0\">
<tr>
<td background=\"tablebg.gif\" class=\"row\" width=\"10%\">[b]Tag[/b]1</td>
<td background=\"tablebg.gif\" class=\"row\" width=\"10%\">[b]Tag2[/b]</td>
<td background=\"tablebg.gif\" class=\"row\" width=\"8%\">[b]Tag3[/b]</td>
</tr>
</table>

"); 

?>

Here's the code I use for which I need it:

<?
$username="username";
$password="password";
$database="database";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM something";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$something=mysql_result($result,$i,"something");
$something=mysql_result($result,$i,"something");
$something=mysql_result($result,$i,"something");

echo (" 

<table width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">

And here is the output produced from the database, which I want to sort by name, if someone clicks one of the tags mentioned earlier:

<tr>
<td valign=\"top\" width=\"10%\">$something</td>
<td valign=\"top\" width=\"10%\">$something</td>
<td valign=\"top\" width=\"8%\">$something</td>
</tr>
</table> 

"); 

$i++;
}

?>


#2 Stu

    Retired P2L Staff

  • Publishing Betazoids
  • PipPipPipPip
  • 1,761 posts
  • Gender:Male

Posted 08 November 2005 - 01:12 PM

why not use this as your query?

$query="SELECT * FROM something ORDER BY name";

or am i missing something?

#3 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 08 November 2005 - 01:46 PM

Stu, on Nov 8 2005, 01:12 PM, said:

why not use this as your query?

$query="SELECT * FROM something ORDER BY name";

or am i missing something?
$query="SELECT * FROM something ORDER BY name ASC";
$query="SELECT * FROM something ORDER BY name DESC";

Minor correction there. ;)

I hope this is what you were asking. :lol:

#4 Fourjays

    Young Padawan

  • Members
  • Pip
  • 30 posts
  • Location:Shropshire United Kingdom

Posted 08 November 2005 - 02:08 PM

If you leave off the ASC or DESC, it will default to ORDER BY DESC (Think thats the right way round).

#5 Stu

    Retired P2L Staff

  • Publishing Betazoids
  • PipPipPipPip
  • 1,761 posts
  • Gender:Male

Posted 08 November 2005 - 02:15 PM

Fourjays, on Nov 8 2005, 07:08 PM, said:

If you leave off the ASC or DESC, it will default to ORDER BY DESC (Think thats the right way round).
thats what i was under the impression too, it will sort the names from a-z by default, or if specified as ASC it will sort from z-a?

#6 Squid

    Young Padawan

  • Members
  • Pip
  • 132 posts
  • Location:Netherlands
  • Interests:Webdesign, php coding, visual basic programming

Posted 08 November 2005 - 03:39 PM

Thanks for all the replies, I appreciate it!

And funny enough, it works. This was a real easy one, I'm ashamed, I could've also found this on google.. Sorry :lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users