PHP looping the columns/fields and values/table dynamically.?

geoff

New member
Hey I'm trying to find a way to loop through the columns of my table and the values of my table dynamically.

For instance here's my columns in the table:
ID
Name
Age
Gender

and the values would be something relative to those fields. I don't want to have to do this.

<th> Name </th> <th> Age </th> <th> Gender </th>
while($row = mysql_fetch_array($results)) {
if($row['name'] != 'id') {
echo '<tr> <td> '.$row['name'].' </td> <td> '.$row['age'].' </td> <td> '.$row['gender'].' </td> </tr>';
}
}

If I want to add another field to my MySQL table I want it to automatically be added to the display. I have no clue how to go about that, everyones been suggesting just hardcode the columns. So I've been going for something like this:

public function showTable() {
$results_col = 'SHOW COLUMNS FROM people';
$results_info = 'SELECT * FROM people';
}

but that's all I have because I don't know how to loop both those results the right way.
 
Back
Top