我有一个包含一行和一列的表。存储的值是整数类型,我想在我的HTML页面中显示该值。 表名为'count',列名为'order_number'。
请告诉我如何在页面中显示此值。
答案 0 :(得分:0)
使用php,你需要连接到mysql并查询数据库,然后回显结果。这是mysqli的一个例子:
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'your_database');
if (mysqli_connect_error()) {
die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
}
$q=$mysqli->query("select * from `your_database`.`your_table` WHERE <some_condition>");
$cnt=0;
while($r=$q->fetch_assoc()) {
$val[$cnt] = $r['field_name'];
$cnt++;
}
$mysqli->close();
//Display first record
echo "The first record is: ".$val[0];
答案 1 :(得分:0)
试试这个例子
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php
$cn=mysql_connect('localhost','user','password') or die(mysql_error());
mysql_select_db('test');
$sql="select order_number from count";
$read=mysql_query($sql,$cn) or die(mysql_error());
$row=mysql_fetch_array($read ) or die(mysql_error());
echo $row['order_number'];
?>
</body>
</html>
答案 2 :(得分:0)
试试这个:
<?php
$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT order_number from count";
$result = mysql_query($sql,$con);
while($row = mysql_fetch_assoc($result)) {
foreach ($row as $col => $val) {
echo $col." = ".$val."<br>";
}
}
?>