logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: MySQL quer results with or without spaces
Author
Brian



Joined: 21 Oct 2005
Posts: 209
Location: Puyallup, WA USA

PostPosted: Sat 17 Oct '09 23:48    Post subject: MySQL quer results with or without spaces Reply with quote

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

PostPosted: Sun 18 Oct '09 7:25    Post subject: Reply with quote

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: 7288
Location: Germany, Next to Hamburg

PostPosted: Mon 19 Oct '09 12:29    Post subject: Reply with quote

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

PostPosted: Mon 19 Oct '09 17:32    Post subject: Reply with quote

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: 7288
Location: Germany, Next to Hamburg

PostPosted: Tue 20 Oct '09 10:21    Post subject: Reply with quote

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


Reply to topic   Topic: MySQL quer results with or without spaces View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner