2013-02-19 45 views
0

我有一個表,一行一列。存儲的值是整數類型,我想在我的HTML頁面中顯示此值。 表名是'count',列名是'order_number'。如何顯示html頁面中列的值?

請告訴我如何在頁面中顯示此值。

+0

什麼樣的表?它是一個數據庫表嗎?什麼樣的數據庫?你如何連接到它?你使用任何服務器端腳本?什麼語言? – Umbrella 2013-02-19 05:18:45

+0

它是一個MySQL數據庫,我使用PHP進行服務器端腳本編寫。 – 2013-02-19 05:23:11

+0

個人而言,我使用MySQLi http://www.php.net/manual/en/book.mysqli.php,但很多人也會推薦PHP數據對象(PDO)http://php.net/manual/en/book。 pdo.php – Umbrella 2013-02-19 05:26:06

回答

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]; 
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> 
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>"; 
     } 
    } 
?>