After making some modifications to my existing script, I created an error:
Notice: Trying to get property of non-object...
I am trying to figure how to identify if the variable $result
is an object so I don't get this error (I am getting the error on this particular line if ($result-> num_rows > 0) {
). Here is what have:
<?php
$sql = "SELECT * FROM input WHERE id =".$_GET["id"];
$result = mysqli_query ($conn,$sql);
if ($result-> num_rows > 0) {
while($row -> $result->fetch_assoc()) {
$myid = $row["id"] ;
$sql2 = "SELECT * FROM output WHERE question_id = $myid ORDER BY date DESC";
$result2 = $conn->query($sql2);
$sql3 = "SELECT COUNT(*) as rowCount FROM output WHERE question_id = '".$myid."'";
$result3 = $conn->query($sql3);
$rowCount= $result3->fetch_assoc();
?>
How can I tell beforehand if this is an object or not?