Jump to content

Archived

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

sackling

Having a default sort with my dropdown

Recommended Posts

I just switched my code around to enable a dropdown to sort my products here is my code:

 

<?php

 

$products_new_array = array();

 

$products_new_query_raw = "select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status from products p, products_description pd, products_to_categories p2c where p.products_id = pd.products_id and pd.language_id = '1' and p.products_id = p2c.products_id and p2c.categories_id in(63)";

 

switch ($_POST['selectboxvalue']) {

case "datenew":

$products_new_query_raw .= " order by p.products_date_added desc";

break;

case "dateold":

$products_new_query_raw .= " order by p.products_date_added";

break;

case "name":

$products_new_query_raw .= " order by pd.products_name";

break;

case "pricelow":

$products_new_query_raw .= " order by p.products_price";

break;

case "pricehigh":

$products_new_query_raw .= " order by p.products_price desc";

break;

}

//echo $products_new_query_raw;

//echo $products_new_query_raw;

$products_new_split = new splitPageResults($products_new_query_raw, 30);

 

if (($products_new_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3'))) {

?>

 

And then my dropdown:

 

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<label for='selectboxvalue'>Sort by:</label>
<select name="selectboxvalue">
   		<option value="name">Popular</option>
	<option value="pricelow">Price Lowest First</option>
       <option value="pricehigh">Price Highest First</option>
       <option value="datenew">Newest</option>
       <option value="dateold">Oldest</option>
</select> 
<input type="submit" name="formSubmit" value="Submit" />
</form>

 

I had to take out the order by in the original code in order for this to work. But I would like for when the page to load to have an order by popular to be instantly loaded. Any help on how to have both?

Share this post


Link to post
Share on other sites

×