Jump to content

Trying to merge 2 queries using UNION


shmideo

Recommended Posts

The queries merge ok and results are correct except I get a notice: "Notice: Use of undefined constant UNION - assumed 'UNION' in...."

But is UNION a constant or is the context wrong?

$query = $query1." ".UNION." ".$query2;

$result = mysqli_query($dbcon, $query) or die('Error getting data');
$num_rows = mysqli_num_rows($result);

Link to comment
https://forums.phpfreaks.com/topic/293042-trying-to-merge-2-queries-using-union/
Share on other sites

Your syntax is wrong. UNION should be inside the quotes otherwise PHP assumes it is defined constant. When it then finds no definition then it assumes (correctly) that it meant to be a string value.

 

$query = $query1 . " UNION " . $query2;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.