Jump to content

mysqli_fetch_assoc in while loop


Biske94

Recommended Posts

Hi people, I have one question about mysqli_fetch_assoc in a while loop.

$query = "SELECT * FROM category ";

$result = mysqli_query($connection, $query);


    while($row = mysqli_fetch_assoc($result))
    {
        $cat_id = $row['cat_id'];
        $cat_title = $row['cat_title'];

        echo $cat_id . " " . $cat_title  ."<br>";
    }

So, how does $row = mysql_fetch_assoc($result) works?

So it loops one row at a time from $results and stores that information in $row until it there is no row to return? 

And this  mysqli_fetch_assoc($result) in while loop iterations is this " array(some rows that it got from $result) "?

$row = mysqli_fetch_assoc($result) is same as $row = array(all rows from $result that are gathered by mysqli_fetch_assoc) ? 

And that means $row is actually an array, and every time it loops the information is not overwriten by new instead it is added? 

Sorry if i confused you with such questions :D

Thanks in advance! :)

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...