Reputation: 59
This codes shows Title for every line. What is my mistake?
foreach($db->query('SELECT * FROM uyeler') as $row) {
echo "<table>
<tr>
<th>ID</th>
<th>Username</th>
<th>Sex</th>
<th>Country</th>
<th>Age</th>
<th>Twitter</th>
<th>Instagram</th>
<th>Snapchat</th>
</tr>";
echo "<tr><td>" .$row['id'] . "</td>";
echo "<td>" .$row['username'] . "</td>";
echo "<td>" .$row['sex'] . "</td>";
echo "<td>" .$row['country'] . "</td>";
echo "<td>" .$row['age'] . "</td>";
echo "<td>" .$row['twitter'] . "</td>";
echo "<td>" .$row['instagram'] . "</td>";
echo "<td>" .$row['snapchat'] . "</td>";
echo "</tr></table>";
}
The table seems like this
ID Username Sex Country Age Twitter Instagram Snapchat
1 canozpey male sadsad 0 twit insta snap
ID Username Sex Country Age Twitter Instagram Snapchat
2 s male Russia 12 test2 sad jgfhf
ID Username Sex Country Age Twitter Instagram Snapchat
3 sda male male 6 male male male
ID Username Sex Country Age Twitter Instagram Snapchat
4 asd female sadasd 0
ID Username Sex Country Age Twitter Instagram Snapchat
5 adsafa female dassd 0
Upvotes: 2
Views: 561
Reputation: 2451
You need to put the wrapping and header outside of the loop - note that you are only looping on content so you don't include those tags in your foreach
.
<table>
<tr>
<th>ID</th>
<th>Username</th>
<th>Sex</th>
<th>Country</th>
<th>Age</th>
<th>Twitter</th>
<th>Instagram</th>
<th>Snapchat</th>
</tr>
<?php
foreach($db->query('SELECT * FROM uyeler') as $row) {
echo "<tr><td>" .$row['id'] . "</td>";
echo "<td>" .$row['username'] . "</td>";
echo "<td>" .$row['sex'] . "</td>";
echo "<td>" .$row['country'] . "</td>";
echo "<td>" .$row['age'] . "</td>";
echo "<td>" .$row['twitter'] . "</td>";
echo "<td>" .$row['instagram'] . "</td>";
echo "<td>" .$row['snapchat'] . "</td>";
echo "</tr>";
}
?>
</table>
Upvotes: 1
Reputation: 426
<table>
<tr>
<th>ID</th>
<th>Username</th>
<th>Sex</th>
<th>Country</th>
<th>Age</th>
<th>Twitter</th>
<th>Instagram</th>
<th>Snapchat</th>
</tr>
<?php
foreach($db->query('SELECT * FROM uyeler') as $row) {
<td><?php echo $row['id'] ?></td>
<td>echo $row['username'] </td>
<td>echo $row['sex'] </td>
<td>echo $row['country'] </td>
<td>echo $row['age'] </td>
}?>
</table>
Upvotes: 0