bsamson Posted November 20, 2006 Share Posted November 20, 2006 Hello, Alright, I have the following code:[code]<?// Grab business name from form$biz = $_POST[business];// define connection infoinclude "db_connect.php";//connects to the DB w/ above credentialsmysql_connect(localhost,$dbuser,$dbpassword);@mysql_select_db($dbname) or die( "Unable to select database");// Build query string$sql = "SELECT business FROM nymob WHERE business LIKE '$biz'";$result = mysql_query($sql) or die(mysql_error());// Creat loop, submit query, and display resultswhile ($row = mysql_fetch_array($result)) {$bizname = $row['business'];$dis = $row['discount'];echo $bizname;echo $dis;}?><p>DONE![/code]Sorry if it's not pretty but just testing right now ... here's the thing ... I have a form on another page where you enter a company name. It would be easy enough to do a search for a business and it returns a discount. However, I would like for the end user to have the ability to enter just 3 letters of the biz and it returns all the businesses that begin with that. The above code does not display anything if I do a search for ABC. However, if I do a search for the complete name, ABC Company all is well and it displays it fine. Any suggestions on what to add / take off in order to have it return results on a partial search.Currently I have 1 company in DB, and obviously it is ABC Company.Thanks for any assistance! Quote Link to comment Share on other sites More sharing options...
btherl Posted November 20, 2006 Share Posted November 20, 2006 Look for [code=php:0]LIKE '$biz%'[/code] instead. If you want case-insensitive search, use [code=php:0]ILIKE '$biz%'[/code] Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 20, 2006 Author Share Posted November 20, 2006 The ILIKE one did not work ... however after using LIKE it worked and oddly enough didnt seem to be case sensitive ... hmmm ...Thanks you soo much! Quote Link to comment Share on other sites More sharing options...
bsamson Posted November 20, 2006 Author Share Posted November 20, 2006 One more quick question ... How would I store those values in an array?For example ... Let's say I did a search for all companies starting w/ 'A'is there a way to store them as such:$business[1][0] = "ABC Company"$discount[1][1] = "50%"and $business[2][0] = "All Good Corp"$discount[2][1] = "30%"etc ... etc ... Any Assistance would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.