⇧
vadnica-logo
My Services About the Project Telegram O meni O meni

mysqli_fetch_assoc() in Detail

The mysqli_fetch_assoc() function is a crucial tool that turns a row from your database into a PHP array, where the keys are the names of your columns. This means you do not have to guess where the data is; you simply call it by its name.

EXAMPLE
RESULT
The result will be displayed here...

Why is this even important? When working on larger projects, database tables change frequently. If you used numerical indexes ($row[0]), your code would break when a new column is added. With associative fetching, your code remains safe and readable.

Using a WHILE Loop

This function is most commonly found inside a while loop. Why? Because with each call, the function "grabs" one row and moves the invisible pointer to the next. When there are no more rows left, the function returns null, and the loop safely stops.