从this question继续现在我需要设置输出样式才发现php不喜欢我放置标签的方式我还试图将其封装在"
和.
中或<?php $row['field'] ?>
但仍然无效。
<table class="table table-hover">
<caption>List All Customers from Customer Table</caption>
<thead>
<tr>
<th>id</th>
<th>Inital</th>
<th>First Name</th>
<th>Last Name</th>
<th>Mobile</th>
<th>Landline</th>
<th>Email</th>
<th>Address</th>
<th>Post Code</th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach ($rows as $row) {
?>
<td><?php $row['clientid']; ?></td>
<td><?php $row['inital']; ?></td>
<td><?php $row['firstname']; ?></td>
<td><?php $row['lastname']; ?></td>
<td><?php $row['mobile']; ?></td>
<td><?php $row['landline']; ?></td>
<td><?php $row['email']; ?></td>
<td><?php $row['address']; ?></td>
<td><?php $row['postcode']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>
它不起作用,显示没有结果。 :(拔出头发!看了另外的问题,但北方足够清楚。
答案 0 :(得分:5)
添加echo
..
<td><?php echo $row['clientid']; ?></td>
<td><?php echo $row['inital']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
<td><?php echo $row['mobile']; ?></td>
<td><?php echo $row['landline']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['address']; ?></td>
<td><?php echo $row['postcode']; ?></td>
答案 1 :(得分:0)
尝试从评论中编辑代码: 可能你只是没有将值推入$ rows数组。
<?php
$rows = array() ;
$result = $dbc->query('SELECT * FROM customer');
if ($result){
while ($row = $query->fetch_assoc()){
$rows[] = $row ; //Put your data in the array first.
}
}
?>
<table>
<tbody>
<tr>
<?php
foreach ($rows as $row) { ?>
<td><?php echo $row['clientid']; ?></td>
<td><?php echo $row['inital']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>