我创建 displaydata ,但我想要下面的条件
function display(){
$get_data = "SELECT * FROM table";
$run_data = mysqli_query($connect, $get_data);
$check_data = mysqli_fetch_array($run_data);
if($check_data == 0){
echo "No post yet";
}
else
{
echo "Display post";
}
}
当查询无时,数据未显示“尚未发布”。
我做错了吗? 提前谢谢。答案 0 :(得分:1)
您可能会使用mysqli_num_rows
并按照以下方式处理:
function display(){
global $connect;
$sql = "SELECT * FROM table";
$result = mysqli_query( $connect, $sql );
if( $result && mysqli_num_rows( $result ) > 0 ){
while( $rs = mysqli_fetch_array( $result ) ){
echo $rs['id'],$rs['title'];/*etc*/
}
mysqli_free_result( $result );
} else {
echo 'No post yet';
}
}
答案 1 :(得分:-1)
你可以使用: -
function display(){
$get_data = "SELECT * FROM table";
$run_data = mysqli_query($connect, $get_data);
$check_data = mysqli_fetch_array($run_data);
$count=count($check_data);
if($count == 0){
echo "No post yet";
}
else
{
echo "Display post";
}
}
或者您可以使用: -
function display(){
$get_data = "SELECT * FROM table";
$run_data = mysqli_query($connect, $get_data);
if(mysqli_num_rows($run_data))
{
while($check_data = mysqli_fetch_array($run_data))
{
print_r($check_data);
}
}
else
{
echo "No post yet";
}
}