私は助けが必要です、私はフェッチされた行に自分自身を試みましたが、それをwhile
ループ内の配列に追加することはできません:次に、後で foreach で then 出力を $rows[] = $row;
構築しようとします。$rows array
どうすればいいですか?
<?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>' ; }
?>