hello i’m going to get array data from for. i have a code but it works not good
in the previous code 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++;
}
}
i have saved this code in the 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>
in here it must be print 2 duration. but it prints only one others have error Notice: Undefined offset: 1 in how to print it by correct?
when i test it to check correct i noticed that:
$result)) {
$duration_c[$cks]= $db_field['duration'];
$cks++;
} echo $duration_c[$cks] //*it prints correct i meant prints 2 test data
}
after that
$result)) {
$duration_c[$cks]= $db_field['duration'];
$cks++;
}
}
echo $duration_c[$cks] //*it prints not correct i meant prints only first test data
how to correct it?
1 Answer