Monday, 26 August 2013

Get dynamic mySQL table column with PHP

Get dynamic mySQL table column with PHP

Normaly all the basic PHP-MYSQL-SELECT tutorials are based on this code
$query = "SELECT * FROM table_name";
$result = mysql_query($query);
$num = mysql_num_rows($results);
if ($num > 0) {
while ($row = mysql_fetch_assoc($result)) {
// You have $row['ID'], $row['Category'], $row['Summary'],
$row['Text']
}
}
but for this I need to know the column name like 'ID', 'Category',
'Summary' or 'Text'. And if I add in phpmyadmin a new column like 'Email',
I also have to add $row['Email'] to the php script.
how can i make this step dynamic?
Thank you!

No comments:

Post a Comment