BBS水木清华站∶精华区
发信人: yanglc (天天改昵称比较的烦), 信区: Linux
标 题: MySQL & PHP--8
发信站: BBS 水木清华站 (Tue Jun 20 22:24:02 2000)
select.php3
<html>
<body>
<?
require("util.php3");
$sql = new MySQL_class;
$sql->Create("phptest");
#
# Selecting a single item
#
echo("<h3>Selecting a single item:</h3>\n");
$name = $sql->QueryItem("select Name from TEST where ID = 4");
echo("<ul>Name is: $name</ul>\n");
#
# Selecting a single row
#
echo("<h3>Selecting a single row:</h3>\n");
$sql->QueryRow("select * from TEST where ID = 4");
$row = $sql->data;
echo("<ul><p>Referencing by array numbers:<ul>\n");
echo("row[0] = $row[0]<br>\n");
echo("row[1] = $row[1]<br>\n");
echo("row[2] = $row[2]<br>\n");
echo("row[3] = $row[3]</ul>\n");
echo("<p>Referencing by column names:<ul>\n");
echo("row[ID] = $row[ID]<br>\n");
echo("row[Name] = $row[Name]<br>\n");
echo("row[Age] = $row[Age]<br>\n");
echo("row[Salary] = $row[Salary]</ul></ul>\n");
#
# Selecting Multiple Rows
#
echo("<h3>Selecting multiple rows</h3>\n");
echo("<p><ul><table border=1 cellpadding=4>\n");
echo("<tr><th>Name</th><th>Age</th></tr>\n");
$sql->Query("Select Name, Age from TEST order by Age");
for ($i = 0; $i < $sql->rows; $i++) {
$sql->Fetch($i);
$name = $sql->data[0];
$age = $sql->data[1];
echo("<tr><td>$name</td><td>$age</td></tr>\n");
}
echo("</table>\n");
echo("<br><br><p>\n");
echo("<a href=\"display.php3?file=select.php3\">Display\n");
echo("the code for this file</a>\n");
?>
</body>
</html>
--
欢迎光临【静园草坪】BBS 站
telnet://bbs.geo.pku.edu.cn
telnet://162.105.20.254
个人主页
http://www2.cs.uestc.edu.cn/~yanglc
※ 来源:·BBS 水木清华站 smth.org·[FROM: 166.111.214.121]
BBS水木清华站∶精华区