user6085744 user6085744 - 1 month ago 4
PHP Question

how to check empty row in a table

How to check empty row in a table using php?

I tried with this code, but it doesnt work:

<?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
}
}
}

Answer

You dont want to use while loop for find number of rows use like this.

$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
}