我有一個屬性表,它有六列。用戶上傳的照片和圖像名稱存儲在列中。計數行中的空列
現在我想要計算每個空行的列數。
我已經能夠做到這一點,但代碼看起來太長,我想編寫高效的代碼,有沒有一種方法來有效地重寫以下內容。
while($data=$select->fetch()){
$imagecounter=0;
if ($data['property_image1'] !== "" && $data['property_image2'] !== "" && $data['property_image3'] !== "" && $data['property_image4'] !== "" && $data['property_image5'] !== "" && $data['property_image6'] !== "") {
echo $imagecounter=6;
} else if ($data['property_image1'] !== "" && $data['property_image2'] !== "" && $data['property_image3'] !== "" && $data['property_image4'] !== "" && $data['property_image5'] !== "") {
echo $imagecounter=5;
} else if ($data['property_image1'] !== "" && $data['property_image2'] !== "" && $data['property_image3'] !== "" && $data['property_image4'] !== "") {
echo $imagecounter=4;
} else if ($data['property_image1'] !== "" && $data['property_image2'] !== "" && $data['property_image3'] !== "") {
echo $imagecounter=3;
} else if ($data['property_image1'] !== "" && $data['property_image2'] !== "") {
echo $imagecounter=2;
} else if ($data['property_image1'] !== "") {
echo $imagecounter=1;
}
}
有更多的數據來,有更多的專欄,但我想檢查只有這六列... – DragonFire
這也是工作 – DragonFire
如果我們想要得到結果是 - 有多少字段不是空的... – DragonFire