Jump to content

Recommended Posts

Hello,

I have searched all over the internet for a solution and have not found what i was looking for so i thought I'd see if you lovely people would be able to help...

 

I'm looking for a script that filters, multiple times, from my MySQl database and the selects exact match results or results closest to the input data.

 

The only way i could think of doing it is like:

$query = mysql_query("SELECT * FROM data WHERE height = '$height' AND WHERE weight LIKE '$weight' AND WHERE shoe LIKE '$shoe' AND WHERE useage LIKE '$useage' AND WHERE skill LIKE '$skill'")  or die(mysql_error());

 

This doesn't work and gives this error

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE weight LIKE '14' AND WHERE shoe LIKE '3' AND WHERE useage LIKE 'touring' A' at line 1

 

I'm really not sure what to try so any help would be appreciated, thanks a lot

Andy

Link to comment
https://forums.phpfreaks.com/topic/62626-mulitiple-filters-in-select/
Share on other sites

Ah excellent, much simpler than i expected thanks.

 

Now one more thing that would be a great help to know is... the code above only shows results if there is an exact match is there an way of printing the results that a close matches and then ordering them in order of closest...  I have search the net for this and couldn't find anything.

 

Thanks in advanced

Andy

Hmmm..  I don't think the LIKE parameter is what you are looking for. It allows you to search for a value that is included in the database, but the database value can include more data. It does not search for similar value - at lest not how I interpret similar. The % tells the query that additional data may come before or after the search string:

 

LIKE '%car' = 'car'

LIKE '%car' = 'race car'

LIKE '%car' != 'carpet'

LIKE 'car%' = 'carpet'

LIKE 'car%' != 'blue carpet'

LIKE '%car%' = 'blue carpet'

 

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.