您好,我将从 for 获取数组数据。我有一个代码,但在之前的代码 cs=2 中效果不佳
for($k=0;$k<$cs;$k++)
{
$SQL = "SELECT duration FROM core_network WHERE location=('".$location_c[$k]."')";
$result = mysql_query($SQL);
$cks="0";
$duration=array();
while ($db_field = mysql_fetch_array($result)) {
$duration_c[$cks]= $db_field['duration']; //*here must save to data
$cks++;
}
}
我已将此代码保存在 search_l.php
<?php include("lib/search_l.php"); ?>
<?php
if($cs!=0){
for($i=0;$i<$cs;$i++)
{
?>
<div id="alarmdisplay">
<table class width="634" border="0" cellspacing="3" cellpadding="3">
<tr class="search">
<td width="256"><?php echo $location_c[$i] ?></td>
<td width="154" class="247"><?php echo $duration_c[$i]
?></td>
<td width="194"> </td>
</tr>
</table>
在这里它必须是打印 2 持续时间。但它只打印另一个有错误注意:未定义的偏移量:1 如何正确打印它?
当我测试它以检查正确时,我注意到:
$result)) {
$duration_c[$cks]= $db_field['duration'];
$cks++;
} echo $duration_c[$cks] //*it prints correct i meant prints 2 test data
}
在那之后
$result)) {
$duration_c[$cks]= $db_field['duration'];
$cks++;
}
}
echo $duration_c[$cks] //*it prints not correct i meant prints only first test data
如何纠正它?