Reputation: 23
Normally I can echo user data from my database using
<?php echo $user_data['fist_name']; ?>
<?php echo $user_data['last_name']; ?>
I want to know if it is possible for me to echo it into this table so it pulls the first name from my database;
<table id="tfhover" class="tftable" border="1">
<tr><td>First Name</td><td>john</td></tr>
<tr><td>Last Name</td><td>doe</td></tr>
</table></body>
Upvotes: 2
Views: 419
Reputation:
Absolutely.
<table id="tfhover" class="tftable" border="1">
<tr><td>First Name</td><td>Last Name</td></tr>
<?php
foreach($users as $user)
echo "<tr><td>" . $user['first_name'] . "</td><td>" . $user['last_name'] . "</td></tr>";
?>
</table></body>
Where users
is an array containing user
objects.
Upvotes: 0
Reputation: 1036
I don't know if your question is clear, but if you get the aray from the db an array you could do this.
<table id="tfhover" class="tftable" border="1">
<tr><td>First Name</td><td><?php $user_data[0]['first_name']?></td></tr>
<tr><td>Last Name</td><td><?php $user_data[0]['first_name']?></td></tr>
</table>
and use to see what do you have in your array and handle it. If you want to print every rows use
for($i=0; $i<count($user_data); ++$i){
echo $user_data[$i]['first_name'];
}
Upvotes: 1