liquinas Posted February 19, 2007 Share Posted February 19, 2007 Hello there php people. I have a question that is probably something simple so my apologies if I sound n00b. Anyway. For the purposes of a car site I have the page inventory.php which lists all the entires in the dbase and sorts the listing by whatever is specified in the form. Like so: <form id="sort" name="sort" method="post" action="inventory.php"> <input type="radio" name="wee" value="Price"> <input type="radio" name="wee" value="Year"> <input type="radio" name="wee" value="Make"> <input type="radio" name="wee" value="Miles"> <input type="radio" name="wee" value="Color"> <input type="radio" name="wee" value="Engine"> <input type="submit" name="Submit" value="Sort Inventory"> inventory.php then receives it at the very top of the code like so: <?php $wee = $_POST['wee']; ?> <html> <head> And that defines the query below: .......... $Order = "ASC"; $ON = "1"; $query = "SELECT * FROM cars WHERE Is_active='$ON' ORDER BY $wee $Order"; $result = mysql_query($query) ........... Anyway. As far as that goes everything works peaches and cream. Problem is, the query fails if nothing is specified from the form, so inventory.php by itself crashes. How can I make it so that if $wee is not specified, a default value to replace it is defined? Thanks in advance for the help. Link to comment https://forums.phpfreaks.com/topic/39141-solved-help-setting-a-default-sort/ Share on other sites More sharing options...
ted_chou12 Posted February 19, 2007 Share Posted February 19, 2007 I believe that you dont need ASC, only when you want the reverse to be done, you use DESC, however, the results are sorted accending by default. Ted Link to comment https://forums.phpfreaks.com/topic/39141-solved-help-setting-a-default-sort/#findComment-188489 Share on other sites More sharing options...
liquinas Posted February 19, 2007 Author Share Posted February 19, 2007 Thanks, noted. However, $Order isn't the problem, it's $wee. $wee defines what category the listing is going to be sorted by, and everything works correctly. I need to have a value that defines $wee when the form is not activated (inventory.php is visited directly). Link to comment https://forums.phpfreaks.com/topic/39141-solved-help-setting-a-default-sort/#findComment-188494 Share on other sites More sharing options...
ted_chou12 Posted February 19, 2007 Share Posted February 19, 2007 oh, try this: <?php $wee = $_POST['wee']; if ($wee == "") {$wee = "default value";} ?> does that give wat you want? Ted Link to comment https://forums.phpfreaks.com/topic/39141-solved-help-setting-a-default-sort/#findComment-188498 Share on other sites More sharing options...
liquinas Posted February 19, 2007 Author Share Posted February 19, 2007 YUS! Thanks so much. May you be blessed with many cookies. Link to comment https://forums.phpfreaks.com/topic/39141-solved-help-setting-a-default-sort/#findComment-188502 Share on other sites More sharing options...
ted_chou12 Posted February 19, 2007 Share Posted February 19, 2007 thanks, you made me hungry. Link to comment https://forums.phpfreaks.com/topic/39141-solved-help-setting-a-default-sort/#findComment-188503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.