我是新来的,如果有人能帮我解决这个问题,我会很高兴。我想从数组$ data中显示不在数组$ time中的时间选择。它应该显示12个中的11个,因为这些数组之间有一个相同的项目。但是它只显示其中一个。希望有人可以帮助我。先谢谢你!
<?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>
我真的不知道上一篇文章是如何替换的,所以我只想在这里编辑。我现在可以显示数组,但输出是这样的。
9时00分零零秒 09:30:00 。 。 。 注意:身份不明的索引:Masa ...... 10:00:00 12:00:00
我不希望出现错误。它实际上是两个数组之间的array_diff。怎么可以跳过?
代码:
<?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;
?>
感谢您的帮助。这是解决我的问题的代码
<?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
}}
?>
再次感谢你。