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
https://forums.phpfreaks.com/topic/27839-need-help-w-simple-db-issue/
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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.