當表格有10行時,我的PHP查詢返回零結果。實際顯示的是PHP表格格式代碼的一部分。當表有數據時,PHP MySQL查詢返回零結果
實際輸出:
0) { // output data of each row while($row = mysql_fetch_assoc($result)) { echo "in: " . $row["in"]. " - Name: " . $row["Name"]. " - Email: " . $row["Email"]. "
"; } } else { echo "0 re
sults"; } mysql_close($conn);?
HTML/PHP代碼:
<div class="about-text">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db";
// Create connection
$conn = mysql_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysql_connect_error());
}
$sql = "SELECT * FROM tablename";
$result = mysql_query($conn, $sql);
if (mysql_num_rows($result) > 0) {
// output data of each row
while($row = mysql_fetch_assoc($result)) {
echo "in: " . $row["in"]. " - Name: " . $row["Name"]. " - Email: " . $row["Email"]. "<br>";
}
} else {
echo "0 results";
}
mysql_close($conn);
?>
</div>
您必須停止使用mysql_ - http://php.net/manual/en/mysqlinfo.api.choosing.php – hanshenrik
退房http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers – hanshenrik