0
這將返回一個空白頁:如何使用MySQL和PHP打印單個單元格的值?
<?php
$con=mysqli_connect("xxx.x.xx.x","user","password","db");
// check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT column FROM table WHERE id=1");
print $result;
mysqli_close($con);
?>
而這個返回的數據:
<?php
$con=mysqli_connect("xxx.x.xx.x","user","password","db");
// check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM table");
while($row = mysqli_fetch_array($result))
{
echo $row['column_1'] . " " . $row['column_2'];
echo "<br>";
}
mysqli_close($con);
?>
什麼是錯的一個代碼塊,以防止其返回的數據?
「mysqli_query」結果無法打印出來,需要提取數據。請參閱手冊中的示例http://us3.php.net/manual/en/mysqli.query.php –
請嘗試以下操作:'$ row = mysqli_fetch_array(mysqli_query($ con,「SELECT column FROM table WHERE id = 1」 ));' 和輸出使用:'echo $ row ['column'];'' – ninty9notout