Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

result: "No Data Found"

I try to display the data of two tables at the same time but that did not work for me.

<?php
require_once 'cont.php';
$resultAll = mysqli_query($con, "SELECT * FROM topic  UNION  SELECT * FROM Image ");
if ($resultAll) {
     while($row[] = $resultAll->fetch_assoc()) {     
     $item = $row;   
     $json = json_encode($item, JSON_NUMERIC_CHECK);     
     } 
} else {
    $json = json_encode(["result" => "No Data Found"]);
}
 echo $json;
$con->close();
?>

I get a message:

result" => "No Data Found

How can show two queries at one time? What error do I have in my code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In order to use UNION statement below are general rules:

  • Every SELECT statement within UNION must have the same number of columns
  • The columns must also have similar data types
  • The columns in every SELECT statement must also be in the same order

As you are using SELECT * FROM table in both your queries, I guess the number of columns aren’t same. Try getting only necessary columns.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading