Jump to content

Need help w/ "simple" DB issue


bsamson

Recommended Posts

Hello,
  Alright, I have the following code:

[code]<?

// Grab business name from form
$biz = $_POST[business];

// define connection info
include "db_connect.php";

//connects to the DB w/ above credentials
mysql_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 results
while ($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!
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.