Jump to content

Can you help me find the error in display/record?


sigmahokies

Recommended Posts

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!
Link to comment
Share on other sites

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().

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.