Jump to content

[SOLVED] Help setting a default sort


liquinas

Recommended Posts

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

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.