Jump to content

Search by ASC or DESC


j05hr

Recommended Posts

I'm trying to make a search form on my website and I want it to search by price in ascending order.  The problem is it doesn't recognize the bigger number in the right way.  I've done this search and this is how it's come back, with a million at the top and then one hundred thousdand? 

 

I think it does it based on the first letter?

 

How can I make it so it does it by size?

 

$searchSQL .= implode(" {$andOr} ", $types) . " ORDER BY `house_price` ASC "; // order by title.

 

1: 1,000,000

5+

House

 

2: 100,000

4

House

 

3: 200,000

1

House

 

4: 300,000

2

House

 

Link to comment
Share on other sites

You can use the MySQL function Format to add the comma's before displaying. If you want the user to input the value as a string with commas in it simply strip them out by str_replacing ',' with ''. That's assuming mysql won't accept an Integer with them in (which I don't think it will, but I've not tested it).

Link to comment
Share on other sites

You can use the MySQL function Format to add the comma's before displaying. If you want the user to input the value as a string with commas in it simply strip them out by str_replacing ',' with ''. That's assuming mysql won't accept an Integer with them in (which I don't think it will, but I've not tested it).

 

This is the way to go.  Integer will not allow commas (it strips anything after). 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.