Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with UNION Query
    text
    copied!<p>I'm trying what seems to be a simple union query for two tables in my database though I am unable to retrieve a successful array result. It should be noted that each table has different columns and that I'd like to create a virtual result (promo AS origin [for the result pulled from the 'venpromo' table] &amp;&amp; vacation AS origin [for the result pulled from the 'vacation' table]) in order to sort the results into different array structures. I've looked everywhere and UNIONS are all using different syntax. Thank you all in advance!</p> <pre><code>&lt;?php require_once('includes/config.php'); $event_query = "SELECT *, promo AS origin FROM venpromo UNION SELECT *, vacation AS origin FROM venpromo ORDER BY popularity DESC"; $event_result = mysql_query($event_query, $connection); while ($event = mysql_fetch_array($event_result)) { if ($event['origin'] == "promo") { $event_array[] = array( 'id' =&gt; $event['id'], 'title' =&gt; $event['calname'], 'start' =&gt; $event['sdate'], 'end' =&gt; $event['edate'], 'color' =&gt; "red", 'url' =&gt; "http://www.norrisportal.com/bulletinpost.php?id=" . $event['id'] . "&amp;hashkey=akdULjsjyUpYyTzOT7" ); } elseif ($event['origin'] == "vacation") { $event_array[] = array( 'id' =&gt; $event['id'], 'title' =&gt; $event['reason'], 'start' =&gt; $event['vacstart'], 'end' =&gt; $event['vacend'], 'color' =&gt; "blue" ); } } echo json_encode($event_array); ?&gt; </code></pre> <p>When visiting the page to view the results, I see 'null'.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload