Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a simple mysql statement 1

Status
Not open for further replies.

smashing

Programmer
Oct 15, 2002
170
US
I'm still a beginner I suppose....

This is my mysql statement
$sql = "SELECT * FROM reserve WHERE $_POST[searchcolum] = '$_POST[searchvalue]' ORDER BY resnum";

Currently it will only get an EXACT match - i.e. a phone number listed in the database as (123) 456-7890 will not be found if searched by looking for 123 456-7890, or if looking just for 7890 e.t.c
I've tried changing
WHERE $_POST[searchcolum] = '$_POST[searchvalue]'
to
WHERE $_POST[searchcolum] LIKE '$_POST[searchvalue]'
but that's not a help. What is ?
Thanks
 
I don't know the state of the phone numbers in your table, which makes it harder. But here goes.

I would take a user input and remove all the spaces, parentheses, and dashes.

Then I would reformat the number as "%999%999%9999", using preg_replace() or some other string manipulation function.

Then I would then query the database as &quot;WHERE <searchcolumn> = '<formatted phone number>'&quot;

A lot of your data issues can be bypassed by forcing user input to a specific format, or by cleaning up the input before insertion into a database. There is no point in storing a phone number in a database as &quot;(123) 456-7890&quot;, because the parentheses, spaces, and dashes are merely formatting, not data. You can store that same phone number as &quot;1234567890&quot;, and format it after retrieval and before output. Want the best answers? Ask the best questions: TANSTAAFL!
 
You are right! I'll do it that way.
Thanks a lot sleipnir214 & have a nice day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top