MySQL中的另一个查询for for循环中的MySQL查询

时间:2015-10-09 10:44:02

标签: php mysql for-loop stored-procedures

我想将来自不同查询的获取结果用作mysql过程中的输入。为此,我编写了以下代码:

$link = mysqli_connect("localhost","root","","localhost") or die("Error " . mysqli_error($link)); 
    if (mysqli_connect_errno()) 
    {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
$query_level1 = "select id,name...from table1; ";
    $query_level1 = "select id,address...from table2;";          
        if ($res_level1=mysqli_query($link,$query_level1))
        {
while ($row_l1 = mysqli_fetch_row($res_level1))
            {
                foreach($row_l1 as $key)
                {
                    $parent_l1 = explode(';',$key);
                    if ( 1 <count($parent_l1))
                    {
                        for ($i = 0;$i < count($parent_l1);$i++)
                        {
$res_level2=mysqli_query($link,$query_level2);
                            -----here fatch the result of $res_level2 into $child array with another for loop 
                            after this step call a procedure: 
                            if (!$link->query("call update_from_level1(" . $child[$k]  . "," . $parent_l1[$i] ")" )) 
                                    {
                                        echo "update_from_level1 : (" . $link->errno . ") ";
                                    }
                           }
                     }
                  }
               }
          }

如果我获取$query_level1的结果,它可以正常工作;但是当我获取$query_level2的结果时,它不起作用。你能帮我解决一下这个问题吗?

1 个答案:

答案 0 :(得分:1)

Mitstake

$query_level1 = "select id,name...from table1; ";
    $query_level1 = "select id,address...from table2;";