如何使用php检查表中的空行?
我尝试使用此代码,但它不起作用:
<?php
ob_start();
session_start();
require 'connection/config.php';
$id = $_GET['id'];
echo $id;
$userid = $_SESSION['userid'];
$sql = "select * from post where id='$id'";
//echo $sql;
$result1 = mysqli_query($conn, $sql);
while ($row1 = mysqli_fetch_array($result1)) {
echo $row1['message'] . "<br>";
$_SESSION['pid'] = $row1['id'];
$userid = $_SESSION['userid'];
echo $userid;
$a = $row1['id'];
$sql = "select * from post inner join likenew on post.id=likenew.postid where likenew.postid='$id' and likenew.userid='$userid'";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
if (empty($row)) { ? >
< a href = "ative.php?id=<?php echo $row['id'];?>" > ready < /a><?php
} else { ? >
< a href = "deactive.php?id=<?php echo $row['id'];?>" > notready < /a><?php
}
}
}
答案 0 :(得分:0)
你不想使用while循环查找行数,就像这样使用。
$sql="select * from post inner join likenew on post.id=likenew.postid where likenew.postid='$id' and likenew.userid='$userid'";
$result=mysqli_query($conn,$sql);
$num=mysqli_num_rows($result)
if($num==0){
?> <a href="ative.php?id=<?php echo $row['id'];?>">ready</a> <?php
}else{
?> <a href="deactive.php?id=<?php echo $row['id'];?>">notready</a><?php
}
答案 1 :(得分:0)
$row = mysqli_fetch_array($result);
if(isset($row['description'])) {
echo "<p>No description</p>";
} else {
echo '<p>'.$row['description'].'</p>';
}
答案 2 :(得分:0)
这是一个例子
$sql = "SELECT fname, lname, mname FROM sks_staffs where id = '$a'";
$query = $this->db->query($sql);
if ($query->num_rows() == 0)
{
// Do something
}
这将有效