简体   繁体   中英

Tutorials on creating a simple item search database using PHP and MySQL?

I have an Excel spreadsheet of some product data, (just a simple table) that I want to put on the web (this isn't serious, I'm just keen on creating my first database on the web).

I want to turn this spreadsheet into database table in MySQL. The columns are: ID, Name, Price and Quantity.

Then create the search page, link it to the database etc. I'm starting with a simple string search here, user types in product name or part of a product name, if it matches it will bring up results along with the other columns.

I've done my fair share of google, there are plenty of tutorials out there if anyone can direct me to one that is for absolute newbies that'll be cool, thanks!

There's really not enough to write a tutorial about.

You create a form that submits to your search script.

This script executes a SELECT query to find rows matching the search term, then displays them.

mysql_connect('localhost', 'username', 'password');
mysql_select_db('database name');

$sql = "SELECT * FROM table WHERE product_name LIKE '%" . mysql_real_escape_string($_GET['search_query']) . "%'";

$result = mysql_query($sql) or die("Error in query $sql: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
    echo "Product: " . $row['product_name'] . "<br />";
}

I highly recommend this book:

http://www.sitepoint.com/books/phpmysql4

It is written for someone in your situation, presumes no PHP or MySQL knowledge, and by the end of the book you'd consider putting up a database and making a page to show search results simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM