du4629 2014-07-14 19:12
浏览 32

array_diff只打印给出一个结果而不是很多

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。