Q
Q
Qeuvec2020-05-13 16:31:22
PHP
Qeuvec, 2020-05-13 16:31:22

How to populate a 2D array in PHP?

Using mysqli_fetch_assoc I'm trying to populate an array with data from the database, but I'm too dumb for this. I don't understand how to do it.
There is a code:

if ($result = mysqli_query($link, 'SELECT * FROM `tests`')) 
            {
                while ( $row = mysqli_fetch_assoc($result))
                {
                    echo 'ВОПРОС:' ,$row['QUESTION'];
                }
            }


Full texts
of ID QUESTION ANSWER VARIANT1 VARIANT2 VARIANT3 VARIANT4 DIFF - in the database For
40 minutes I tried to push this data into a two-dimensional array, and then I screwed up all the code of my attempts. When writing, it constantly fills one line and I do not understand how to do ++ to a line during while. In tyrnet, either everything is filled in manually, or it's too complicated ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
unwrecker, 2020-05-13
@Qeuvec

Where is the two-dimensional array actually in the code?
So, for example, the $dumb array will be filled two-dimensionally:

$dumb=array();
if ($result = mysqli_query($link, 'SELECT * FROM `tests`')) 
            {
                while ( $row = mysqli_fetch_assoc($result))
                {
                    $dumb[]=$row;
                }
            }

F
FanatPHP, 2020-05-13
@FanatPHP

$data =  $link->query('SELECT * FROM `tests`')->fetch_all(MYSQLI_ASSOC);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question