0

I have got the results from the several sql phrase in php-MySQL. My $sql1 and the result query phrases is as like below.

$sql1= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 ...
 where condition
$result1=  mysqli_query($con,$sql1);

But I have the 9 sql query phrases as like above code. selected columns are same in the 9 sql query. That is

$sql2= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 ...
 where condition
$result2=  mysqli_query($con,$sql2);
...
$sql9= "SELECT code_co.code, code_co.disease_co, code_en.disease_en, ds.ds_url 
 FROM code_co
 LEFT JOIN code_en ON code_en.code = code_co.code
 LEFT JOIN note ON note.code = code_co.code
 ...
 where condition
$result9=  mysqli_query($con,$sql9);

Finally I want to get the intersection of the 9 results, but MySQL is not supported. So I want to solve that by php code. That is array_intersect() function. But I am at a loss how I use that.

 while($row1= mysqli_fetch_array($result1))

 while($row2= mysqli_fetch_array($result2))
     ....
 while($row9= mysqli_fetch_array($result9))

$intersect = array_intersect($row1, $row2, $row3, $row4, ...., $row9);
print_r($intersect);
mysqli_close($con);
?>

There is no error message but, nothing is displayed. I first use array_intersect function in this code. please, Give me a piece of advice. Thank you for your concern.

1 Answer 1

1

Doing it with PHP is going to be DEATHLY, and highly resource consumer. If you just made an INNER JOIN between all big queries using as condition in the ON the key field you want to intersect, you'd directly have the intersection you look for.

Other thing, maybe nothing is displayed because you're not throwing any error to the screen, check your PHP error configuration in your system and application to enable them where developing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.