I want to use the fetch results from different queries as an input in a mysql procedure. To do this, I wrote the following code:
$link = mysqli_connect("localhost","root","","localhost") or die("Error " . mysqli_error($link));
if (mysqli_connect_errno())
{
printf("Connect failed: %s
", 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 . ") ";
}
}
}
}
}
}
If I fetch the result of $query_level1
, it works properly; but when I fetch the result of $query_level2
, it didn't work. Could you help me to figure out the problem?
Mitstake
$query_level1 = "select id,name...from table1; ";
$query_level1 = "select id,address...from table2;";