0

I'm using PHP to paginate the data, but I am trying to figure how I can group the data by price, name, etc. I know I will need to use an array of some sort

SELECT PRODUCTS.name,p_id,sku, image, description, model, CATEGORIES.category
id
WHERE PRODUCTS.name LIKE  '%$title%'
ORDER BY p_id ASC $pages->limit";

Any suggestions?

Thanks

1 Answer 1

1

No need for an array of some sort, use the same ORDER BY like this:

ORDER BY p_id, PRODUCTS.name, CATEGORIES.category, models ASC $pages->limit

UPDATE

Lets say you have a select that posts the order by, something like:

<select name="order">
      <option value="price">price</option>
      <option value="name">name</option>
</select>

Then you clean the post and put it in the query like

$order = mysql_real_escape_string($_POST["order"]);
//and then
SELECT * FROM table ORDER BY $order; 
Sign up to request clarification or add additional context in comments.

8 Comments

I am planning on using a Jumpmenu to sort the data Individually
sort it individually meaning?
Like a jump menu that would consist of Sort By: then the options are Price low to high, high to low, Best Selling
Yeah then you would need to post some variables and the query would change a lot.
I can give the link of the jump menu item, and define variables for each, and put the variable in the order by statement?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.