| Bob Stearns 2005-01-24, 8:56 pm |
| Shaun wrote:
> Hello ALT.PHP.SQL users :),
>
> I am having a small problem in this line which is a text box input
> search function:
>
> 1) $sql="SELECT * FROM pschamber WHERE Business_Name LIKE
> '%".$_POST['name']."%'";
>
> What it currently does is a google type search on the business names
> looking for rough matches. What I want to do is have it so when the
> SELECT input is say 'A' it only returns items from the field
> 'Business_Name' beginning with the selected input 'A'.
>
> I believe what I have to change from my line 1) is this section:
>
> 1a) LIKE '%".$_POST['name']."%'";
>
> Does anyone have any suggestions or weblinks to give me a rough ideas
> on how to have it match the first character.
>
> Thanks for your interest and help,
>
> Shaun
Just remove the first occurrence of the % (percent) which is SQL's wild
card match as many characters as possible. This change will match from
the left as many character as the user enters. Note that you are
allowing unedited user input into your query which can cause
catastrophic problems with your application.
LIKE '".$_POST['name']."%'"
|