yandoo Posted February 19, 2008 Share Posted February 19, 2008 Hi there, Im looking to create a drop down that's options display how a user will view the records by. e.g. View By: Dropdown options (Price, date, ID) So then the user can select how they would like to view the records via the drop down...instead of using exisiting hyperlinks. Ultimately i would like to have just a single page for all View by options...so im thinking i will need to have some kind of IF ELSE staement to detemine how to view the record.... Im not really sure where to begin here (although i do pick it up quite quickly), if anybody could give me some advice and help that would be brilliant!! Thank You Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/ Share on other sites More sharing options...
revraz Posted February 19, 2008 Share Posted February 19, 2008 What I do is on my table header, I make them hyperlinks. So they can click on any header and it will sort by it. Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-471019 Share on other sites More sharing options...
yandoo Posted February 19, 2008 Author Share Posted February 19, 2008 HHmmm im not really sure i follow you....perhaps i dont pick it up that quick i tried creating it with a submit button and got this far ...... <!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> <form id="form1" name="form1" method="post" action="view.php?recordID_id=<?php echo $row_Animal['AnimalID']; ?>"> <p>View By: <select name="Animal" id="AnimalID"> <option value="">select</option> <?php do { ?> <option value="<?php echo $row_Animal['AnimalID']?>"><?php echo $row_Animal['AnimalType']?></option> <?php } while ($row_Animal = mysql_fetch_assoc($Animal)); $rows = mysql_num_rows($Animal); if($rows > 0) { mysql_data_seek($Animal, 0); $row_Animal = mysql_fetch_assoc($Animal); } ?> </select> </p> <p> <input type="submit" name="Submit2" value="Submit" /> </p> </form> <p></p> </body> </html> This is suppose to be working....According to coder..so im little confused... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-471115 Share on other sites More sharing options...
ILYAS415 Posted February 19, 2008 Share Posted February 19, 2008 Hmm im not entirely sure what your trying to do (the replies confused me) sooo here it goes.... Okay im thinking that your trying to make a select box from which the user can select different ways to view results... heres my way.... <select name=orderby> <option value="-">Select one...</option> <option value="date" onclick="window.location='?orderby=date';">Date</option> <option value="price" onclick="window.location='?orderby=price';">Price</option> <option value="id" onclick="window.location='?orderby=id';">ID</option> </select> <? if (isset($_GET['orderby']){ $orderby= $_GET['orderby']; }else{ $orderby="date"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD $sql= mysql_query("SELECT * FROM table ORDER BY $orderby DESC"); //SQL QUERY CAN BE MODIFIED EVEN MORE //WHATEVER ELSE YOU WANT ?> Hope that helps. I tested on my own server it works. Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-471138 Share on other sites More sharing options...
yandoo Posted February 20, 2008 Author Share Posted February 20, 2008 Hi there, Yes that sounds exaclty what im looking for, sorry for the confusion...it was long day Thank You Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-471507 Share on other sites More sharing options...
yandoo Posted February 22, 2008 Author Share Posted February 22, 2008 Hello, Ive tried the code and am wondering...Does it require a Submit button for it to work???? Becaus at present the options are listed the drop down but nothing happens when selecting an order by option. If so, is it possiblle to do make the options in the drop down so they are hyperlinked??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-474044 Share on other sites More sharing options...
ifis Posted February 22, 2008 Share Posted February 22, 2008 I think you might also look at using a switch statement. With the switch statement you could set a default view. switch ($view) { case 'view 1': echo ' ....'; break; case 'view 2': echo ' ....'; break; default: echo 'default view'; } but you will have to set the view variable first. Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-474068 Share on other sites More sharing options...
yandoo Posted February 22, 2008 Author Share Posted February 22, 2008 Hi, I slightly added to the select query and to give me the following: <? if (isset($_GET['orderby']){ $orderby= $_GET['orderby']; }else{ $orderby="AnimalID"; } //CHECKING TO SEE IF THE PERSON HAS CHOSEN TO ORDER BY A CERTAIN FIELD $sql= mysql_query("SELECT * FROM animal ORDER BY $orderby DESC"); $sql = mysql_query($query_sql, $woodside) or die(mysql_error()); $row_sql = mysql_fetch_assoc($sql); $totalRows_sql = mysql_num_rows($sql); ?> At the moment when selecting a drop down option nothing happens... i notice that in the browser it says "http://localhost/woodside/index.php?orderby=Name" So it kind of looks like it works... It doesnt work in IE at all, but only in Firefox....I think it has something to do with the <?....should i be using <?php instead??? When i try to make this change i get an erro message saying : Parse error: syntax error, unexpected '{' in C:\wamp\www\Woodside\index.php on line 244 I have then tried to echo the query to see if it works by: <?php echo $row_sql['AnimalID']; ?> No results are dislpayed at all?? If anybody can please please help me id be so happy Thank You Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-474078 Share on other sites More sharing options...
yandoo Posted February 23, 2008 Author Share Posted February 23, 2008 Hi again Trying to order the record by drop down options but it says: It says "the query is empty"....??? <head> </head> <body> <?php if (isset($_GET['orderby'])) { $orderby= $_GET['orderby']; }else{ $orderby="AnimalID"; } ?> <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> Please anybody?? why is it not working? Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-474168 Share on other sites More sharing options...
ILYAS415 Posted February 23, 2008 Share Posted February 23, 2008 Hmm just realised that code only works in Mozilla... hmmmm. 1sec im just playing around with some codes Quote Link to comment https://forums.phpfreaks.com/topic/91968-view-records-by-drop-down-options/#findComment-474446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.