Home > Backend Development > PHP Tutorial > How to Separate MySQL Column Values Using mysqli_fetch_array?

How to Separate MySQL Column Values Using mysqli_fetch_array?

Susan Sarandon
Release: 2024-10-30 14:09:52
Original
325 people have browsed it

How to Separate MySQL Column Values Using mysqli_fetch_array?

Unable to Separate MySQL Column Values with mysqli_fetch_array

In this scenario, you're encountering an issue where the mysqli_fetch_array function is combining all the column values into a single column, making it challenging to access them individually.

To resolve this, consider utilizing the following approach:

<code class="php">$posts = array();
while($row = mysqli_fetch_array($result)) {
    $posts[] = $row;
}</code>
Copy after login

By storing the entire row as an element in the $posts array, you can access individual values later using a nested loop:

<code class="php"><?php 
foreach ($posts as $row) 
{ 
    foreach ($row as $element)
    {
        echo $element . "<br>";
    }
}
?></code>
Copy after login

This will print all values in the columns, one per line. Alternatively, you can also access specific elements directly using the array index:

<code class="php">$postId = $row[0];</code>
Copy after login

The above is the detailed content of How to Separate MySQL Column Values Using mysqli_fetch_array?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template