PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun May 31, 2020 12:45 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Tue Jan 27, 2009 9:18 am 
Offline
Forum Newbie

Joined: Tue Jan 27, 2009 9:13 am
Posts: 1
Hi there Guys

I have a small problem with the sort-order when using "SELECT DISTINCT" for a search script. This is what I have:

<select name="type" class="textField" id="select2">
<?php
if ($type == ""){
print " <option value=\"0\" selected>All Types</option>";
}else{
print " <option value=\"0\" >All Types</option>";
}
$res = dbsql("SELECT DISTINCT (type) FROM carsz");
while (($row = dbfetch($res)) != NULL) {
$res2 = dbsql("SELECT * FROM type WHERE id = '$row[type]' ORDER BY type ASC");
$row2 = dbfetch($res2);
if ($type == $row2[id]){
print "<option value=\"".$row2[id]."\" selected>".$row2[type]."</option>\n ";
}else{
print "<option value=\"".$row2[id]."\">".$row2[type]."</option>\n ";
}
}
?>
</select>


Basically there are 2 tables:
1) table with listings
2) table with types

So the "type" in table 1 is just an ID that refer back to table 2. But when I use the script the sort order of the different types are not alphabetical.

PLEASE HELP
Andy


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group