简体   繁体   English

使用PHP和MySQL创建简单项目搜索数据库的教程?

[英]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). 我有一些要放在网络上的产品数据(只是一个简单的表格)的Excel电子表格(这并不严重,我只是热衷于在网络上创建我的第一个数据库)。

I want to turn this spreadsheet into database table in MySQL. 我想将此电子表格转换为MySQL中的数据库表。 The columns are: ID, Name, Price and Quantity. 列为:ID,名称,价格和数量。

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! 我已经完成了对Google的应有份额,如果有人可以引导我进入绝对适合新手的教程,那么这里有很多教程,谢谢!

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. 此脚本执行SELECT查询以查找与搜索词匹配的行,然后显示它们。

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 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. 它是为您所处的环境而编写的,假定您不具备PHP或MySQL知识,并且在本书结尾时,您将考虑建立数据库并制作一个页面来简单显示搜索结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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