order by not working with. help!

Reply

Join Date: Feb 2009
Posts: 10
Reputation: swit is an unknown quantity at this point 
Solved Threads: 0
swit swit is offline Offline
Newbie Poster

order by not working with. help!

 
0
  #1
Apr 8th, 2009
Hello people, i have the following code though it is not giving me the exact results i want. i would like the code to order by the name but the order by doesnt seem to be executed. here is the code;
  1. $query2 = "select * from jos_categories where id = '".$row['cid']."' ORDER BY name ASC";
  2. $result2 = mysql_query($query2, $conn);
  3. $idrow = mysql_fetch_assoc($result2);
  4. $link = sefRelToAbs('index.php?option=' . $option . '&task=view&limit=0&id=' .$idrow['id'] . '&Itemid=' . $Itemid);
thanx in advance for any help.
Last edited by swit; Apr 8th, 2009 at 11:42 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 91
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: order by not working with. help!

 
0
  #2
Apr 8th, 2009
What is your output then? Also there appears to be a mistake in your query. I presume ID is a number, then there is no need for single quotes. So...
  1. where id = '".$row['cid']."'
becomes
  1. where id = ".$row['cid']."
Last edited by brechtjah; Apr 8th, 2009 at 1:17 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 10
Reputation: swit is an unknown quantity at this point 
Solved Threads: 0
swit swit is offline Offline
Newbie Poster

Re: order by not working with. help!

 
0
  #3
Apr 9th, 2009
Originally Posted by brechtjah View Post
What is your output then? Also there appears to be a mistake in your query. I presume ID is a number, then there is no need for single quotes. So...
  1. where id = '".$row['cid']."'
becomes
  1. where id = ".$row['cid']."
Thank you for your reply,
well, it appears that with or without the quotes, it works ok.
the output is it brings back a list of all the categories i want thou it doesnt order them by name in alphabetical order as i want them. it seems to be ignoring the order by statement.
Output is
• Secondary Schools
• Primary school
• Special Needs Institutions
• Vocational School
• Nursery school

please, any help will be appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: order by not working with. help!

 
0
  #4
Apr 9th, 2009
Originally Posted by swit View Post
Hello people, i have the following code though it is not giving me the exact results i want. i would like the code to order by the name but the order by doesnt seem to be executed. here is the code;
  1. $query2 = "select * from jos_categories where id = '".$row['cid']."' ORDER BY name ASC";
  2. $result2 = mysql_query($query2, $conn);
  3.  
  4. $link = sefRelToAbs('index.php?option=' . $option . '&task=view&limit=0&id=' .$idrow['id'] . '&Itemid=' . $Itemid);
thanx in advance for any help.

can you try these 2 options if there is a difference on the output.

  1. 1. $idrow = mysql_fetch_array($result2, MYSQL_ASSOC);
  2.  
  3. or
  4.  
  5. 2. $idrow = mysql_fetch_array($result2);
Last edited by rm_daniweb; Apr 9th, 2009 at 6:34 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 10
Reputation: swit is an unknown quantity at this point 
Solved Threads: 0
swit swit is offline Offline
Newbie Poster

Re: order by not working with. help!

 
0
  #5
Apr 9th, 2009
Originally Posted by rm_daniweb View Post
can you try these 2 options if there is a difference on the output.

  1. 1. $idrow = mysql_fetch_array($result2, MYSQL_ASSOC);
  2.  
  3. or
  4.  
  5. 2. $idrow = mysql_fetch_array($result2);
Thanx for your reply,
however i have tried the two options and non of them changes the out put. perhaps i should post some more code to make it clearer. i have a distinct just before the while statement. maybe it is what is messing things up. the code seems to order by the id instead and overlook the orderby name statement.
  1. $query = "select distinct cid from jos_artband";
  2. $result = mysql_query($query, $conn);
  3. $num = mysql_num_rows($result);
  4.  
  5. while ($row=mysql_fetch_assoc($result))
  6. {
  7.  
  8. $query2 = "select * from jos_categories where id = ".$row['cid']." ORDER BY name ASC";
  9. $result2 = mysql_query($query2, $conn);
  10. $idrow = mysql_fetch_array($result2, MYSQL_ASSOC);
  11. $link = sefRelToAbs('index.php?option=' . $option . '&task=view&limit=0&id=' .$idrow['id'] . '&Itemid=' . $Itemid);
  12.  
  13. if($idrow['name'] != "")
  14. {
  15. echo '<tr>';
  16. echo '<td align="center"><a href="' . $link . '">&bull;&nbsp;&nbsp;&nbsp;'.$idrow['name'] .'</a> </td>
  17. </tr>';
  18. }
  19. }
  20. echo '</table>';

Any help will be highly appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 164
Reputation: rm_daniweb is an unknown quantity at this point 
Solved Threads: 10
rm_daniweb rm_daniweb is offline Offline
Junior Poster

Re: order by not working with. help!

 
0
  #6
Apr 9th, 2009
like what you said....before the output are the ff:
Output is
• Secondary Schools
• Primary school
• Special Needs Institutions
• Vocational School
• Nursery school

is this a "NAME" column inside your database or "SCHOOL"? can you post your database structure.
Last edited by rm_daniweb; Apr 9th, 2009 at 11:13 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC