title: MySQL query to select specific data
body: <p>I would like to display the data that belongs to any of my users when they login to the site, as well as the name of each table (they completed offers on them).</p>
  
  <p>This is the code I used, but when I add it it's not working. </p>
  
  <pre><code>$result = mysql_query('SELECT *,\'tbl1\' AS tablename FROM (SELECT * FROM  table1 WHERE user_id='$user_id') as tbl1 UNION SELECT *,\'tbl2\' AS tablename FROM (SELECT * FROM table1 WHERE user_id='$user_id') as tbl2'. ' ORDER BY `date` DESC');
  
  while($sdata = mysql_fetch_array($result)){
    echo $sdata['date'];
    echo $sdata['tablename'];
    echo $sdata['user_reward'];
  }
  </code></pre>
  
  <p>Where did I make a mistake?</p>