how to retun results for a misspelled query

I am working on a site that has people ask for the name of a business.(Sorry if you read my other question) How can I build into the form a way to have the person spell part of the name, or only enter in one or two letters?
I am relatively new at this so any help would be appreciated.

Brian

In the form… in the input field maxlength… SQL will allow you to search for parts of words… Check out using LIKE with wildcards in the
WHERE statement. If you have no clue what a WHERE statement is never mind how to use LIKE in it with a “wildcard???”… You can check the manual ( http://dev.mysql.com/doc/mysql/en/SELECT.html for WHERE) ( http://dev.mysql.com/doc/mysql/en/Strin … tions.html for LIKE and wildcards) or here ( http://sqlcourse.com/select.html ).

Good luck and I hope this helps.

Lig,
Seems like you are the man on this forum so maybe you can help out a little.

I am trying to learn how to use an <href=> tag in my html.
I used this line of code:
B

passed it to this:

$db=mysql_select_db($db_name,$conn) or die(mysql_error());
$sql = "SELECT id,restName, restAddress, restCity, restState,restZip, restCuisine, restCuisine02,restType, restPhone, restFax, restWeb, deliveryRadius,
delivery_time, restHours, restFeature, restMap FROM $table_name WHERE restName = like b%;

$result= mysql_query($sql,$conn) or die(mysql_error());

//start the while loop
while ($row= mysql_fetch_array($result)) {
$id=$row[‘id’];
$restName=$row[‘restName’];
$restAddress=$row[‘restAddress’];
$restCity=$row[‘restCity’];
etc, etc,

and I get an error:

Parse error: parse error, expecting T_STRING' orT_VARIABLE’ or `T_NUM_STRING’ in /home/western/public_html/show_rest_alph.php on line 21

I am just starting to use the url pass of the data, however, I cannot seem to get it to work. I understand the queries perfectly, but it is the php that is giving me problems.

Thanks for the help,
Brian

First off I hope you realize by passing the variable in the URL is using the $_GET method (register_globals = off) so to access it you must initially refer to it as $_GET[‘restName’]. I don’t see it anywhere in your code so that might be the first problem.

Hope that helps.

I think thats where he was trying to use it. Replace b with $_GET[‘b’] (or better yet, assign $_GET[‘b’] to the var $b and use $b instead).

Sorry to be bothersome. Last question is how would I pass a variable along that contains the letter for which the user is tying to look. In other words, on my “search_rest_alph.php” page, I would like to allow the user to select a letter of the alphabet, and then on the “see_rest_alph.php” page, I would like the letter they chose to be in a variable that allows me to only have one line of code for the search query. The only other way I could think to do it is to have 26 loops, which I am thinking would be overkill.

Brian

Uh… thats what you have. Just do what I said, and it’ll get the variable from the querystring.

OK on the form in your HTML I would suggest you have a drop down list of the letters (Name = “Letter”). Depending on what action you are using (GET or POST) for the form that is how you access the variable. Then use the variable in the SELECT statement.

Psuedocode Example:

on submition of form
    work_variable = $_POST['letter']  
    SQL = "SELECT * FROM table WHERE name LIKE "work_variable%";"
    run query and handle data
else
    display POST form
    input text box name = letter size = 1

To learn about forms and working with them check out codewalkers.com in the tutorials/basics section. There is a tutorial just on forms.

Sponsor our Newsletter | Privacy Policy | Terms of Service