Passing while () to a variable from while () to php

Suppose I have a request

$array = array();
$sql = mysql_query("SELECT * FROM table");
while($row=mysql_fetch_array($sql)){
 $data = $row['data'];
}
$array = $data;

Now, how can I get each value of $ data from while in array () ie $ array

+3
source share
5 answers
$array = array();
$sql = mysql_query("SELECT * FROM table");

while ($row = mysql_fetch_array($sql)) {
    $array[] = $row['data'];
}
+7
source

adding each line of $ to the $ data array
for reference: http://php.net/types.array

Note that there is no such thing as a “while () array”. There are only arrays.

+1
source

$data . $data[], $data , $array [], , , $data .

+1

"" , :

$array = array();
$sql = mysql_query("SELECT * FROM table");
while($row=mysql_fetch_array($sql)){
   $array[] = $row['data'];
}

:

   $array[] = $row['data'];

:

+1
$array = array();
$sql = mysql_query("SELECT * FROM table");
while($row=mysql_fetch_array($sql)){
   $array[] = $row['data'];
}

further u can use

$array['data']

and u can also use mysql_fetch_assoc($sql)insteadmysql_fetch_array($sql)

0
source

Source: https://habr.com/ru/post/1763347/


All Articles