sigmahokies Posted September 21, 2015 Share Posted September 21, 2015 Hi everyone, I am trying to display the record on website, but I could not. I checked many times, I don't see any error, seem to me, all structure is properly, but still showing error. Can you help me to find this error? 42 $show = "SELECT FirstName, LastName FROM Members"; 43 $result2 = mysqli_query($Garydb,$show) or die("Could not show record"); 44 45 if ($result3 = mysqli_num_rows($result2) or die("error display")) { 46 while ($row = mysqli_fetch_assoc($result3) or die("Could not fetch to display")) { 47 echo "<table><tr><td>".$row."</td></tr></table>"; 48 } 49 } 50 else { 51 echo "<table><tr><td>No display record</td></tr></table>"; 52 } the error showing is line 46 - Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, integer given in. Thank you in advance! Quote Link to comment https://forums.phpfreaks.com/topic/298254-can-you-help-me-find-the-error-in-displayrecord/ Share on other sites More sharing options...
Ch0cu3r Posted September 21, 2015 Share Posted September 21, 2015 mysqli_fetch_assoc() expects the mysqli_result object ($result2), this is returned by mysqli_query(). You are getting the error because you are passing the numbers of rows ($result3) to mysqli_fetch_assoc. You should be passing $result2 Not sure why you are using or die for mysql_num_rows and mysqli_fetch_assoc. It only needs to be used with mysqli_query -well actually it is better to use trigger_error rather than die(). Quote Link to comment https://forums.phpfreaks.com/topic/298254-can-you-help-me-find-the-error-in-displayrecord/#findComment-1521274 Share on other sites More sharing options...
sigmahokies Posted September 21, 2015 Author Share Posted September 21, 2015 Moderator, I just use die() to find the the error. Quote Link to comment https://forums.phpfreaks.com/topic/298254-can-you-help-me-find-the-error-in-displayrecord/#findComment-1521275 Share on other sites More sharing options...
sigmahokies Posted September 21, 2015 Author Share Posted September 21, 2015 Moderator, are you telling me that I should change like this: 42 $show = "SELECT FirstName, LastName FROM Members"; 43 $result2 = mysqli_query($Garydb,$show) or die("Could not show record"); 44 45 if ($result2 = mysqli_num_rows($result2) or die("error display")) { 46 while ($row = mysqli_fetch_assoc($result2) or die("Could not fetch to display")) { 47 echo "<table><tr><td>".$row."</td></tr></table>"; 48 } 49 } 50 else { 51 echo "<table><tr><td>No display record</td></tr></table>"; 52 } Are they correct? Quote Link to comment https://forums.phpfreaks.com/topic/298254-can-you-help-me-find-the-error-in-displayrecord/#findComment-1521276 Share on other sites More sharing options...
Barand Posted September 21, 2015 Share Posted September 21, 2015 Advanced Member, do it like this $show = "SELECT FirstName, LastName FROM Members"; $result2 = mysqli_query($Garydb,$show) or die("Could not show record"); echo "<table>"; if (mysqli_num_rows($result2) > 0) { while ($row = mysqli_fetch_assoc($result2) ) { echo "<tr><td>" . $row['FirstName']. " " . $row['LastName'] . "</td></tr>"; } } else { echo "<tr><td>No display record</td></tr></table>"; } echo "<table>"; After 40+ posts you should have found the code tags by now. 1 Quote Link to comment https://forums.phpfreaks.com/topic/298254-can-you-help-me-find-the-error-in-displayrecord/#findComment-1521279 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.