0

I would like to get the results only from the second query in this multiquery statement. Presently, the way I have it constructed I get the results from both query statements:

$query = ("call calcfields2_new('$_SESSION[Userid]');");
$query .= "SELECT * FROM CalcFields WHERE Userid=$_SESSION[Userid]"; 

if (mysqli_multi_query($dbc, $query)) {
do {
    if ($result = mysqli_store_result($dbc)) {
        while ($row = mysqli_fetch_assoc($result)) {

    $array1[]=$row;
        }
        mysqli_free_result($result);
        }
    if (mysqli_more_results($dbc)) {
    }
} 
while (mysqli_next_result($dbc));
}
}

echo(json_encode($array1));     
user2232681
  • 839
  • 4
  • 16
  • 33

1 Answers1

0

Does this do it for ya?

$query = ("call calcfields2_new('$_SESSION[Userid]');");
$query .= "SELECT * FROM CalcFields WHERE Userid=$_SESSION[Userid]";

preg_match_all("/(?:(.*?)\s.*?(?:;|$))/",$query,$first_word);

if(mysqli_multi_query($dbc,$query)){
    do{
        if($result=mysqli_store_result($dbc)){
            if(array_shift($first_word[1])=="SELECT"){
                while($row=mysqli_fetch_assoc($result)) {
                    $array1[]=$row;
                }
            }
            mysqli_free_result($result);
        }
    } while(mysqli_more_results($dbc) && mysqli_next_result($dbc));
}
// if($error_mess=mysqli_error($dbc)){echo "Error: $error_mess";}

echo(json_encode($array1));     
mickmackusa
  • 43,625
  • 12
  • 83
  • 136