Php 返回一行并避免其中的空字段
如何将一行返回到表格中并避免字段为空Php 返回一行并避免其中的空字段,php,Php,如何将一行返回到表格中并避免字段为空 <?php $o = mysqli_query("SELECT * FROM orders ORDER BY po_number DESC LIMIT 1"); echo 'The Following Order Information has been submited.'; echo '<table width="70%" border="5" align="center">'; while($row = mysqli_fetch_ar
<?php
$o = mysqli_query("SELECT * FROM orders ORDER BY po_number DESC LIMIT 1");
echo 'The Following Order Information has been submited.';
echo '<table width="70%" border="5" align="center">';
while($row = mysqli_fetch_array($o)) {
echo '<tr>';
foreach($row as $field) {
echo '<td>' . htmlspecialchars($field) . '</td>';
}
echo '</tr>';
}
echo '</table>';
?>
在foreach()之前使用数组过滤器($row)
。它从array()
中删除所有空元素
echo“已提交以下订单信息”;
回声';
while($row=mysqli\u fetch\u数组($o)){
$row=array_filter($row);//此行
回声';
foreach($行作为$字段){
回显“”。htmlspecialchars($field)。“”;
}
回声';
}
回声';
foreach($行作为$字段){
if(设置($field)&&!空($field)){
回显“”。htmlspecialchars($field)。“”;
}
在foreach()之前使用array\u过滤器($row)
echo 'The Following Order Information has been submited.';
echo '<table width="70%" border="5" align="center">';
while($row = mysqli_fetch_array($o)) {
$row = array_filter($row); //This line
echo '<tr>';
foreach($row as $field) {
echo '<td>' . htmlspecialchars($field) . '</td>';
}
echo '</tr>';
}
echo '</table>';
foreach($row as $field) {
if(isset($field) && !empty($field)) {
echo '<td>' . htmlspecialchars($field) . '</td>';
}