我有一个包含 20 行和 10 列的表单,元素 ID 由 _r1、_r2 等区分,而不是从我的查询中手动分配所有值,我希望循环遍历它们。
就像是
//Set all mileage fields to empty
for ($i = 1; $i <= 20; $i++) {
$strTravelDate_r.$i = "";
$strHBE_r.$i = "";
$strPassenger_r.$i = "";
$strCongestionCode_r.$i = "";
$strTravelReason_r.$i = "";
$strAddress1_r.$i = "";
$strAddress2_r.$i = "";
$strDistance_r.$i = "";
$strRate_r.$i = "";
$strLineAmount_r.$i = "";
}
//Get mileage claims
$sql_miles = 'SELECT * FROM `tblsaved_mileage` WHERE `strUsername`="'.addslashes($username).'"';
$rs_miles = mysql_query($sql_miles);
$count_miles = mysql_num_rows($rs_miles);
$i = 1;
if ($count_miles > 0) {
while ($row_miles = mysql_fetch_array($rs_miles)) {
$strTravelDate_r.$i = $row_miles['strTravelDate'];
$strHBE_r.$i = $row_miles['strHBE'];
$strPassenger_r.$i = $row_miles['strPassenger'];
$strCongestionCode_r.$i = $row_miles['strCongestionCode'];
$strTravelReason_r.$i = $row_miles['strTravelReason'];
$strAddress1_r.$i = $row_miles['strAddress1'];
$strAddress2_r.$i = $row_miles['strAddress2'];
$strDistance_r.$i = $row_miles['strDistance'];
$strRate_r.$i = $row_miles['strRate'];
$strLineAmount_r.$i = $row_miles['strAmount'];
$i = $i + 1;
}
}
但我得到了很多
Notice: Undefined variable: strTravelDate_r in ........
Notice: Undefined variable: strHBE_r in ........
Notice: Undefined variable: strPassenger_r in ........