yandoo Posted February 25, 2008 Share Posted February 25, 2008 Hi there, Im bit stuck and was hoping some expert advice please Basically i have a simple drop down menu thats options display how a user will order records of a database by... For example: Drop Down options - ID, Type, Name. It is suppose to bring records from my DB and order then by the option selected... Heres what i have so far...: <?php require_once('Connections/woodside.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php if (isset($_GET['orderby'])) { $orderby= $_GET['orderby']; }else{ $orderby="AnimalID"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD ?> <select name=orderby> <option value="-">Select one...</option> <option value="ID" onclick="window.location='?orderby=AnimalID';">ID</option> <option value="name" onclick="window.location='test8.php?orderby=Name';">Name</option> <option value="animaltype" onclick="window.location='test8.php?orderby=AnimalTypeID';">Animal Type</option> </select> <?php $test= mysql_query("SELECT * FROM animal ORDER BY $orderby DESC"); $test = mysql_query($query_test, $woodside) or die(mysql_error()); $row_test = mysql_fetch_assoc($test); $totalRows_test = mysql_num_rows($test); ?> <?php echo $row_test['AnimalID']; ?> </body> </html> There is a mesage on screen saying query is always empty??? It doesnt do anything with IE 7. But in Firefox it will link to the page but no records are displayed (when this happens addres bar on browser says: /test8.php?orderby=Name) and it still says Query enpty. I tried to echo out query to see if it works and nothing appears... Please help me, think im close to getting this to work, but could really use some help. Thank You Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/ Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 $test = mysql_query($query_test, $woodside) or die(mysql_error()); should be: $test = mysql_query($test) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475764 Share on other sites More sharing options...
Chris92 Posted February 25, 2008 Share Posted February 25, 2008 You are trying to set a mysql_query funtion into a mysql_query funtion and then array it. It should be <?php $test= mysql_query("SELECT * FROM `animal` ORDER BY `{$orderby}` DESC", $woodside) or die(mysql_error()); $row_test = mysql_fetch_assoc($test); $totalRows_test = mysql_num_rows($test); ?> Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475766 Share on other sites More sharing options...
cooldude832 Posted February 25, 2008 Share Posted February 25, 2008 $test = mysql_query($query_test, $woodside) or die(mysql_error()); should be: $test = mysql_query($test) or die(mysql_error()); Not technically $woodside could be a var we don't see that is the mysql connection resource. however I have a problem with the $query_test part as yuo don't define the query thus yes it is empty so php is keeping it real as the kids like to say Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475782 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi there and thank you everyboy who has replied! I have made changes accordingly and it now works with IE7 and also the "Query is empty" message no longer appears....instead is another saying "no Database Selected". How can this be? because the table & database name is all correct??? Thank All for Your help!!! Tom Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475794 Share on other sites More sharing options...
Chris92 Posted February 25, 2008 Share Posted February 25, 2008 You don't have any database selected mysql_select_db('database'); Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475822 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hey, thats brilliant thank you im obviously quite a noob at this Manged to ovrecome that little obstacle only to hit another (blast!) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #4' at line 1 Thank You Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475914 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Repost your current code, you are using the resource incorrectly. Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-475918 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi there, Heres the full code....theres not much to it really.. <?php require_once('Connections/woodside.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php if (isset($_GET['orderby'])) { $orderby= $_GET['orderby']; }else{ $orderby="AnimalID"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD ?> <select name=orderby> <option value="-">Select one...</option> <option value="ID" onclick="window.location='test8.php?orderby=AnimalID';">ID</option> <option value="name" onclick="window.location='test8.php?orderby=Name';">Name</option> <option value="animaltype" onclick="window.location='test8.php?orderby=AnimalTypeID';">Animal Type</option> </select> <?php mysql_select_db($database_woodside, $woodside); $test= mysql_query("SELECT * FROM `animal` ORDER BY `{$orderby}` DESC", $woodside) or die(mysql_error()); $test = mysql_query($test) or die(mysql_error()); $row_test = mysql_fetch_assoc($test); $totalRows_test = mysql_num_rows($test); ?> <?php echo $row_test['AnimalID']; ?> </body> </html> Thank You Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476196 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 You are doing your query twice $test= mysql_query("SELECT * FROM `animal` ORDER BY `{$orderby}` DESC", $woodside) or die(mysql_error()); $test = mysql_query($test) or die(mysql_error()); change to $test= ("SELECT * FROM `animal` ORDER BY `{$orderby}` DESC"); $result = mysql_query($test) or die(mysql_error()); $row_test = mysql_fetch_assoc($result); $totalRows_test = mysql_num_rows($result); Also, you may want to use two different variables here instead of reusing the one, makes it easier to troubleshoot. Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476207 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hey there, thats brilliant thank you very much for helping me its greatly appreciated I made the suggested change and it works a charm.... In order to test it fully i added a Repeat region to display all of the records by using: <?php do { ?> <?php echo $row_test['AnimalID']; ?> <?php } while ($row_test = mysql_fetch_assoc($test)); ?> This would then hopefully display all the AnimalIDs of the records.... I must be doing something totally wrong as i get another Resource error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Woodside\test8.php on line 32 I have created many repeat regions before so am confussed why the hell its not working?? Thank you all for your help so far, i certainly wouldnt have got to where i am with out your support Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476262 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Hey there, thats brilliant thank you very much for helping me its greatly appreciated I made the suggested change and it works a charm.... In order to test it fully i added a Repeat region to display all of the records by using: <?php do { ?> <?php echo $row_test['AnimalID']; ?> <?php } while ($row_test = mysql_fetch_assoc($test)); ?> This would then hopefully display all the AnimalIDs of the records.... I must be doing something totally wrong as i get another Resource error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Woodside\test8.php on line 32 I have created many repeat regions before so am confussed why the hell its not working?? Thank you all for your help so far, i certainly wouldnt have got to where i am with out your support in his code use <?php } while ($row_test = mysql_fetch_assoc($result)); ?> instead of your <?php } while ($row_test = mysql_fetch_assoc($test)); ?> Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476274 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi there, Thank You very much indeed, thats it!! Thanks again to everybody for helping me!! Its all for my university project and im going to give you peeps a mention and dedication because you all been so kind! Thanks again Tom p.s. Topic Solved doesnt appear at bottom of my threads anymore?? Tried looking at forum post on it and it said should be there now?? Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476291 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 It's still missing in action I think. Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476293 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Ok cool, ill look out for that 1.. Ive just done so more testing and it isnt properly working....It only displays the default (ORDERBY ID) records....When i select Name or Type option from drop down nothing happens??? Oh man, how gutting.. Feel really crap now Heres the code with all the modifications (please NOTE included drop down code and added table to display results): <?php require_once('Connections/woodside.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php if (isset($_GET['orderby'])) { $orderby= $_GET['orderby']; }else{ $orderby="AnimalID"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD ?> <select name=orderby> <option value="-">Select one...</option> <option value="ID" onclick="window.location='test8.php?orderby=AnimalID';">ID</option> <option value="name" onclick="window.location='test8.php?orderby=Name';">Name</option> <option value="animaltype" onclick="window.location='test8.php?orderby=AnimalTypeID';">Animal Type</option> </select> <?php mysql_select_db($database_woodside, $woodside); $test= ("SELECT * FROM `animal` ORDER BY `{$orderby}` DESC"); $result = mysql_query($test) or die(mysql_error()); $row_test = mysql_fetch_assoc($result); $totalRows_test = mysql_num_rows($result); ?> <?php do { ?> <?php echo'<table width="10" border="0">'; echo '<tr>'; echo '<td>Animal ID</td>'; echo'<td>Animal Type</td>'; echo'<td> </td>'; echo '<td> </td>'; echo '<td> </td>'; echo '</tr>'; echo'<tr>'; echo'<td>'; echo $row_test['AnimalID']; echo'</td>'; echo'<td>'; echo $row_test['AnimalTypeID']; echo'</td>'; echo'<td> </td>'; echo'<td> </td>'; echo'<td> </td>'; echo'</tr>'; echo'</table>'; ?> <?php } while ($row_test = mysql_fetch_assoc($result)); ?> </body> </html> If anybody can help still that be sweet, but i think im loosing will to live. Thank You Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476308 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 try removing the {} brackets in: $test= ("SELECT * FROM `animal` ORDER BY `{$orderby}` DESC"); to show: $test= ("SELECT * FROM `animal` ORDER BY `$orderby` DESC"); Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476312 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi there, Thanks for reply, this is really wierd....I tested it in Firefox and it works...just not in IE7? Why could that be?? Thanks Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476319 Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 try adding <?php ini_set('error_reporting',E_ALL); ?> see if you get an error Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476323 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi, I dont get any error message on either IE7 (doesnt change orderby of records on selection) and Firefox 2.0 (works perfectly).... This is strange??? Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476329 Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 take the backticks off orderby $test= ("SELECT * FROM `animal` ORDER BY $orderby DESC"); Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476330 Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Not as strange as you think. For one, you are using javascript for your select/options. If JS is turned off, you will have problems. Second, IE and FF treat forms differently, so one may ignore errors while the other halts on it. Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476331 Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Try this: Change: <select name=orderby> <option value="-">Select one...</option> <option value="ID" onclick="window.location='test8.php?orderby=AnimalID';">ID</option> <option value="name" onclick="window.location='test8.php?orderby=Name';">Name</option> <option value="animaltype" onclick="window.location='test8.php?orderby=AnimalTypeID';">Animal Type</option> </select> To: <form name="reorder" action="test8.php" method="GET"> <select name="orderby"> <option "-">Select one...</option> <option value="AnimalID" onclick="document.reorder.submit();">ID</option> <option value="Name" onclick="document.reorder.submit();">Name</option> <option value="AnimalTypeID" onclick="document.reorder.submit();">Animal Type</option> </select></form> Tell me if that works any better Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476338 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi there, I tried removing back ticks & JavaScipt is enabled on IE7...Also using <?php ini_set('error_reporting',E_ALL);?> and NO errors are generated on either browser at all??? Also... I changed the drop down code to your suggestion with form and there is no change?? Still woirks fine with Firefox (both with and without suggested change) and NOT with IE7. Im 100% IE7 has JS enabled as i use it on other pages fine! Surely the code cant be far off as it is working perfectly in Firefox?? Thanks Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476347 Share on other sites More sharing options...
darkfreaks Posted February 25, 2008 Share Posted February 25, 2008 $test= ("SELECT * FROM animal ORDER BY $orderby DESC"); Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476355 Share on other sites More sharing options...
yandoo Posted February 25, 2008 Author Share Posted February 25, 2008 Hi there, Again theres no change, with or without change in quotes on SELECT query, it works fine in Firefox and NOT in IE7... This is just silly now Thanks Link to comment https://forums.phpfreaks.com/topic/92875-drop-down-query/#findComment-476360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.