我需要帮助,我尝试了获取的行,但无法将其附加到while
循环中的数组中:$rows[] = $row;
然后尝试稍后在 foreach 中构建$rows array
then 输出。
我该怎么做呢?
<?php
$query = $dbc->query('SELECT * FROM customer');
$rows = array();
while ($row = $query->fetch_assoc()) {
echo $row['clientid'].' '.$row['inital'].' '.$row['firstname'].' '.$row['lastname'].' '.$row['mobile'].' '.$row['landline'].' '.$row['email'].' '.$row['address'].' '.$row['postcode'];
}
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>
</td>
<?php } ?>
最后我是这样做的
<?php
$query = $dbc->query('SELECT * FROM customer');
if ( mysqli_num_rows( $query ) > 0 )
{
while ( $row = mysqli_fetch_array( $query, MYSQLI_ASSOC ))
{
echo "<tr><td>".$row['clientid']."</td><td>".$row['inital']."</td><td>".$row['firstname']."</td><td>".$row['lastname']."</td><td>".$row['mobile']."</td><td>".$row['landline']."</td><td>".$row['email']."</td><td>".$row['address']."</td><td>".$row['postcode']."</td></tr>";
}
echo '</tbody></table>' ;
}
else { echo '<div class="alert alert-error">
There are currently no records.
</div>' ; }
?>