[英]Database Connected, but no data found
I have created this page, I have put dummy content into MySQL database, I have ran the same query in phpMyAdmin and it brings back data, yet on the web page it is bringing up "No Data". 我已经创建了此页面,已将虚拟内容放入MySQL数据库,我在phpMyAdmin中运行了相同的查询,并带回了数据,但是在网页上却显示了“无数据”。
Have I missed something? 我错过了什么吗? (obviously blanked out database details)
(显然清空了数据库详细信息)
<?php
// Connection Info
$host ='localhost';
$user ='-----';
$pass ='-----';
$dbname ='-----';
$conn = new mysqli($host, $user, $pass, $dbname);
if($conn->connection_errno){
echo "Connection Failed" . $conn->connect_error;
exit();
}
?>
<?php
$query = "SELECT * FROM posts";
$result = $conn->query($query);
if($results->num_rows > 0){
while($row = $result->fetch_assoc()){
echo $row['title'];
}
echo"We Have Data";
} else {
echo"No Data";
}
?>
Change the following line 更改以下行
if($results->num_rows > 0){
to 至
if($result->num_rows > 0){
He typo mistake friend 他错字了朋友
Make following changes in to your code 对您的代码进行以下更改
From if($results->num_rows > 0){ 从if($ results-> num_rows> 0){
To 至
if($result->num_rows > 0){ if($ result-> num_rows> 0){
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.