| | |
order by not working with. help!
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2009
Posts: 10
Reputation:
Solved Threads: 0
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;
thanx in advance for any help.
PHP Syntax (Toggle Plain Text)
$query2 = "select * from jos_categories where id = '".$row['cid']."' ORDER BY name ASC"; $result2 = mysql_query($query2, $conn); $idrow = mysql_fetch_assoc($result2); $link = sefRelToAbs('index.php?option=' . $option . '&task=view&limit=0&id=' .$idrow['id'] . '&Itemid=' . $Itemid);
Last edited by swit; Apr 8th, 2009 at 11:42 am.
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...
becomes
PHP Syntax (Toggle Plain Text)
where id = '".$row['cid']."'
PHP Syntax (Toggle Plain Text)
where id = ".$row['cid']."
Last edited by brechtjah; Apr 8th, 2009 at 1:17 pm.
•
•
Join Date: Feb 2009
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
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...
becomesPHP Syntax (Toggle Plain Text)
where id = '".$row['cid']."'
PHP Syntax (Toggle Plain Text)
where id = ".$row['cid']."
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.
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
•
•
•
•
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;
thanx in advance for any help.PHP Syntax (Toggle Plain Text)
$query2 = "select * from jos_categories where id = '".$row['cid']."' ORDER BY name ASC"; $result2 = mysql_query($query2, $conn); $link = sefRelToAbs('index.php?option=' . $option . '&task=view&limit=0&id=' .$idrow['id'] . '&Itemid=' . $Itemid);
can you try these 2 options if there is a difference on the output.
PHP Syntax (Toggle Plain Text)
1. $idrow = mysql_fetch_array($result2, MYSQL_ASSOC); or 2. $idrow = mysql_fetch_array($result2);
Last edited by rm_daniweb; Apr 9th, 2009 at 6:34 am.
•
•
Join Date: Feb 2009
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
can you try these 2 options if there is a difference on the output.
PHP Syntax (Toggle Plain Text)
1. $idrow = mysql_fetch_array($result2, MYSQL_ASSOC); or 2. $idrow = mysql_fetch_array($result2);
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)
$query = "select distinct cid from jos_artband"; $result = mysql_query($query, $conn); $num = mysql_num_rows($result); while ($row=mysql_fetch_assoc($result)) { $query2 = "select * from jos_categories where id = ".$row['cid']." ORDER BY name ASC"; $result2 = mysql_query($query2, $conn); $idrow = mysql_fetch_array($result2, MYSQL_ASSOC); $link = sefRelToAbs('index.php?option=' . $option . '&task=view&limit=0&id=' .$idrow['id'] . '&Itemid=' . $Itemid); if($idrow['name'] != "") { echo '<tr>'; echo '<td align="center"><a href="' . $link . '">• '.$idrow['name'] .'</a> </td> </tr>'; } } echo '</table>';
Any help will be highly appreciated.
•
•
Join Date: Jan 2007
Posts: 164
Reputation:
Solved Threads: 10
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.
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.
![]() |
Similar Threads
- Shopping Cart Not Working (ASP.NET)
- javascript onclick is not working in IE7 & IE6 (JavaScript / DHTML / AJAX)
- Problems With Xp Boot Loader (Windows NT / 2000 / XP)
- about:blank hijacked, solutions offered not working (Viruses, Spyware and other Nasties)
- CD-ROm isnt working correctly (Storage)
- Search not working right... (Viruses, Spyware and other Nasties)
- My games still arent working. (Troubleshooting Dead Machines)
- .htaccess not working.! (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: PHP to read XML and write into MySQL ?
- Next Thread: Input value submit to php
| Thread Tools | Search this Thread |
apache api array beginner binary body broken cakephp checkbox class cms code computing cron curl database date date/time delete display dynamic echo email error file files filter folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert ip javascript joomla limit link list login mail memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex remote script search seo server sessions sms snippet source space sql static syntax system table thesishelp tutorial update upload url validator variable video web webdesign wordpress xml youtube





