多个循环一起运行

时间:2018-07-04 16:47:07

标签: php

 $a_forms = array("a_GG", "a_FF");
 $sql = "SELECT name, field FROM categories WHERE enabled = '1' ";
 $result = mysqli_query($con,$sql);

 $Others = array();
  while($row = mysqli_fetch_array($result)) {
    $Other_names[] = $row['name'];
    $Other_fields[] = $row['db_field'];
}


  for ($i=0;$i<count($a_forms);$i++) {   
    if ($a_forms[$i] == "a_FF") {

        $dforms_sql = "SELECT * 
                        FROM a_FF 
                        where id=".$id;                                                              

        $dforms_result = mysqli_query($con,$dforms_sql);

        while ($forms_row = mysqli_fetch_array($dforms_result)) {
            for ($i=0; $i<count($Other_fields); $i++) {

                echo "<tr><td colspan='3'>".$Other_names[$i]."</td></tr>";
            }
        }
    } elseif ($a_forms[$i] == "a_GG") {
        $dforms_sql = "SELECT * 
                        FROM a_GG where id=".$id;                                                                
        $dforms_result = mysqli_query($con,$dforms_sql);
        while($forms_row = mysqli_fetch_array($dforms_result)) {
            echo 'Other cool stuff';
        }
    }
} //END (first) For Loop

因此,由于某种原因,如果第二个for循环存在$ Other_field,它将仅显示a_FF的IF语句。但是,如果数组= a_FF和a_GG并且$ other_field的for循环不存在,它将同时显示它们。所以很明显,for循环正在破坏某些东西,但是我不知道该怎么办。有人有什么想法吗?

0 个答案:

没有答案