//mysql数据库的sql
CREATE TABLE user( id int(5) DEFAULT '0' NOT NULL AUTO_INCREMENT, name varchar(20), city varchar(20), postcode varchar(10),address varchar(100), password varchar(10), level tinyint(2) DEFAULT '0',right tinyint(2),email varchar(40), PRIMARY KEY (id), UNIQUE id (id));
INSERT INTO myuser VALUES (1,'王友','北京','100083','北京市海淀区学院路',111,0,0,'wangyou000@263.net');
INSERT INTO myuser VALUES (2,'金风','武汉','430071','武汉市武昌区水果湖',111,0,0,'jinfeng000@263.net');
INSERT INTO myuser VALUES (3,'常丽','襄樊','441021','襄樊市襄城区南街',111,0,0,'changli000@263.net');
1. Search All
<title> Search All </title>
<body>
<H2 align=center>
The following are all the contents of the user database:
?
$db = mysql_connect ("localhost", "root");
mysql_select_db ("MySite", $db);
$result = mysql_query ("SELECT * from user", $db);
echo "<table border=1>\n";
echo "<tr><td>id</td><td> name </td>";
echo "<td> City </td><td> postcode </td>";
echo "<td> address </td><td> grade </td>";
echo "<td> permissions </td><td> email address </td>";
echo "</tr>\n";
while ($myrow = Mysql_fetch_row ($result))
{
printf ("<tr><td>%s</td><td>%s</td>", $myrow [0], $myrow [1]);
printf ("<td>%s</td><td>%s</td>", $myrow [2], $myrow [3]);
printf ("<td>%s</td><td>%s</td>", $myrow [4], $myrow [6]);
printf ("<td>%s</td><td>%s</td></tr>\n", $myrow [7], $myrow [8]);
}
echo "</table>\n";
?>
</body>
2. According to the ID query
<body>
<title>
Query by ID
</title>
?
$db = mysql_connect ("localhost", "root");
mysql_select_db ("MySite", $db);
if ($id) {
$result = mysql_query ("SELECT * from user WHERE id= $id", $db);
$myrow = Mysql_fetch_array ($result);
printf ("
printf ("1.ID number%sn<br>", $myrow ["id"]);
printf ("2. Name:%sn<br>", $myrow ["name"]);
printf ("3. Cities:%sn<br>", $myrow ["City"]);
printf ("4 Zip:%sn<br>", $myrow ["postcode"]);
printf ("5. Address:%sn<br>", $myrow ["addresses"]);
printf ("6. Rank:%sn<br>", $myrow ["level"]);
printf ("7. Email address:%sn<br>", $myrow ["email"]);
printf ("<a href="%s "> Continue query </a>", $PATH _info);
}
Else
{
$result = mysql_query ("SELECT * from user", $db);
if ($myrow = mysql_fetch_array ($result))
{
printf ("
do {
printf ("%s<a href="%s?id=%s ">%s </a><br>\n",
$myrow ["id"], $PATH _info, $myrow ["id"], $myrow ["name"]);
}
while ($myrow = Mysql_fetch_array ($result));
}
Else
{
echo "Sorry, no data!" ";
}
}
?>
</body>