Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: MySQL quer results with or without spaces |
|
Author |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Sat 17 Oct '09 23:48 Post subject: MySQL quer results with or without spaces |
|
|
In my db I have a part number BR 6747.
If I type in the search query, BR 6 or br 67, etc, I get a match. I have some basic pattern matching but if I type:
BR6747 (<- no space) there is no match, in the db the part is BR 6747.
How can I get a match when the user enters without a space but the data in the db has a space?
The opposite is easy enough, but this way is proving to be difficult (for me).
Thanks. |
|
Back to top |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Sun 18 Oct '09 7:25 Post subject: |
|
|
Just to follow up here is more info:
I have "BR 6742" or what ever in the database.
If the user enters BR6742, or BR6 or BR 6 I want all of those to match.
It is easy with REGEX or LIKE adding a % to match:
* user input: BR 6742
to db value:
* db value: BR6742
But if the db has value: BR 6742 and the user enters BR6742 (no space) I am finding it very difficult to understand how to match this format.
Yes, I repeated myself, I am sorry for that. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 19 Oct '09 12:29 Post subject: |
|
|
maybe you should try to form the user input as you need it. In PHP I'd use preg_split and str_ireplace.
Second thing is you can show an input example over the input box the user sees. Or you have two input boxes like one for the letters and one for the numbers and put it together in your programming. |
|
Back to top |
|
Brian
Joined: 21 Oct 2005 Posts: 209 Location: Puyallup, WA USA
|
Posted: Mon 19 Oct '09 17:32 Post subject: |
|
|
Yes, I am thinking of splitting this into multiple queries.
Break it up into sections, the numbers isolated, the letters isolated, make an array and then do a "LIKE" or "SOUNDS LIKE" match on each part of the user query. This would be possible.
--
Brian |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 20 Oct '09 10:21 Post subject: |
|
|
I didn't think of splitting the query. I though of something like this
Code: |
<input type="text" name="letter" /><input type="text" name="number" />
|
Code: |
$seach_string = mysql_escape_string($_POST['letter']).' '.mysql_escape_string($_POST['number']);
|
|
|
Back to top |
|
|
|
|
|
|