PHP MySQL Get Column Names When Repeating All Records

$query = mysql_query("SELECT * FROM mytable"); while ($row = mysql_fetch_assoc($query)) { //How to echo column names and values here? } 

Is it possible to repeat table column names and values ​​when repeating throughout the table in a while ?

+6
source share
3 answers

You can use foreach loop

 $query = mysql_query("SELECT * FROM mytable"); while ($row = mysql_fetch_assoc($query)) { foreach($row as $key => $value) { print "$key = $value <br />"; } } 
+13
source
 $query = mysql_query("SELECT * FROM mytable"); while ($row = mysql_fetch_assoc($query)) { print_r($row); } 
+1
source

try it. column_name is the same u name used in the table

 echo $row['column_name']; 
-2
source

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


All Articles