I'm new here and I would be very glad if anyone could help me solving this problem. I want to display the selection of time that are not in array $time from array $data. It supposed to display 11 out of 12 since the there is one same item between those array. However it only display one of it. Hopefully somebody can help me. Thank you in advanced!
<?php
$q = "SELECT masa FROM pra_temujanji where status = 'Diterima' and hari = '$hari' and Doktor = '$Doktor'";
$select = mysql_query($q);
$time = mysql_fetch_array($select);
$qry = "SELECT Masa FROM masa_temujanji";
$qid = mysql_query ($qry);
$data = mysql_fetch_array($qid);
foreach($time as $elem) $time[$elem['masa']];
foreach($data as $elem) $data[$elem['Masa']];
ksort($data); ksort($time);
$waktu = array_diff($data, $time);
?>
<option value="<?php print_r($waktu['Masa'])?>"><?php print_r($waktu['Masa'])?></option>
</select>
I dont really know how either the previous post will be replace or not so i just edit in here. I can display the array now but the output is like this.
09:00:00 09:30:00 . . . Notice: Unidentified index: Masa ...... 10:00:00 12:00:00
I dont want the Error to appear. Its actually the array_diff between both array. How can it be skipped?
The code:
<?php
$q = "SELECT masa FROM pra_temujanji where status = 'Diterima' and hari = '$hari' and Doktor = '$Doktor'";
$select = mysql_query($q);
while($time = mysql_fetch_array($select)):
$qry = "SELECT Masa FROM masa_temujanji";
$qid = mysql_query ($qry);
while ($data = mysql_fetch_array($qid)):
$waktu = array_diff($data, $time);
?>
<option value="<?php print_r($waktu['Masa'])?>"><?php print_r($waktu['Masa'])?></option>
<?php
endwhile;
?>
</select>
<?php
endwhile;
?>
Thank you for your help. Here is the code that solved my problem
<?php
$q = "SELECT masa FROM pra_temujanji where status = 'Disahkan Lulus' and hari = '$hari' and Doktor = '$Doktor'";
$select = mysql_query($q);
while ($time = mysql_fetch_array($select)){
$masa[] = $time['masa'];
}
if(isset($masa)){
$qry = "SELECT Masa FROM masa_temujanji";
$qid = mysql_query ($qry);
while ($data = mysql_fetch_array($qid)){
$Masa[] = $data['Masa'];
}
$waktu = array_diff($Masa, $masa);
foreach( $waktu as $key => $value){
?>
<option value="<?php echo $value ?>"><?php echo $value ?></option>
<?php } }
else{
$qry = "SELECT Masa FROM masa_temujanji";
$qid = mysql_query ($qry);
while ($data = mysql_fetch_array($qid)){
$Masa[] = $data['Masa'];
}
//$waktu = array_diff($Masa, $masa);
foreach( $Masa as $key => $value){
?>
<option value="<?php echo $value ?>"><?php echo $value ?></option>
<?php
}}
?>
Thank you again.