943,719 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 562
  • PHP RSS
Apr 8th, 2009
0

order by not working with. help!

Expand 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;
PHP Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
swit is offline Offline
10 posts
since Feb 2009
Apr 8th, 2009
0

Re: order by not working with. help!

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...
PHP Syntax (Toggle Plain Text)
  1. where id = '".$row['cid']."'
becomes
PHP Syntax (Toggle Plain Text)
  1. where id = ".$row['cid']."
Last edited by brechtjah; Apr 8th, 2009 at 1:17 pm.
Reputation Points: 26
Solved Threads: 9
Junior Poster in Training
brechtjah is offline Offline
92 posts
since Nov 2008
Apr 9th, 2009
0

Re: order by not working with. help!

Click to Expand / Collapse  Quote originally posted by brechtjah ...
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...
PHP Syntax (Toggle Plain Text)
  1. where id = '".$row['cid']."'
becomes
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
swit is offline Offline
10 posts
since Feb 2009
Apr 9th, 2009
0

Re: order by not working with. help!

Click to Expand / Collapse  Quote originally posted by swit ...
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;
PHP Syntax (Toggle Plain Text)
  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.

PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 13
Solved Threads: 12
Junior Poster
rm_daniweb is offline Offline
165 posts
since Jan 2007
Apr 9th, 2009
0

Re: order by not working with. help!

Click to Expand / Collapse  Quote originally posted by rm_daniweb ...
can you try these 2 options if there is a difference on the output.

PHP Syntax (Toggle Plain Text)
  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.
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
swit is offline Offline
10 posts
since Feb 2009
Apr 9th, 2009
0

Re: order by not working with. help!

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.
Reputation Points: 13
Solved Threads: 12
Junior Poster
rm_daniweb is offline Offline
165 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP to read XML and write into MySQL ?
Next Thread in PHP Forum Timeline: Input value submit to php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC