Note that there are some explanatory texts on larger screens.

plurals
  1. POMerging returned results from two querys for log type feature
    text
    copied!<p><strong>Information</strong></p> <p>I am currently making a history/log page that will show the users payment history with my website.</p> <p>The two tables are <code>tasks</code> and <code>payouts</code></p> <p><code>tasks</code> is a table full of tasks a user can complete and earn money. The columns returned that I use are <code>tasks.title</code>, <code>tasks.payment</code> and <code>tasks.timestamp</code></p> <p><code>payouts</code> is a table that saves information when a user pays out their earnings. The columns returned that I use are <code>payouts.processor</code>, <code>payouts.amount</code> and <code>payouts.timestamp</code></p> <p><strong>Problem</strong></p> <p>I need to run both query's, merge them ( maybe with a type field so I can easily display them differently when I use a foreach on output ) and then order by timestamp DESC.</p> <p><strong>Attempt</strong></p> <p>My only attempt has been fruitless, All I did was run both the querys and then use <code>array_push</code> which didnt add anything to the end of the array.</p> <p><strong>Question</strong></p> <p>What would be the best way to have two querys results merged while adding a field called <code>LOG_TYPE</code> so when outputting I can do something like this</p> <pre><code>foreach($data as $row){ if($row['LOG_TYPE'] == 1){ // Display Payout } else { // Display Task } } </code></pre> <p><strong>Conclusion</strong></p> <p>Any questions will be answered ASAP and any edits will be displayed below. Thank you.</p> <p><strong>EDIT</strong></p> <p>As requested, here are the two querys I am using.</p> <pre><code> $STH = $this-&gt;database-&gt;prepare('SELECT * FROM tasks WHERE completed_by = :userid ORDER BY timestamp DESC'); $STH-&gt;execute(array(':userid' =&gt; $user)); $data = $STH-&gt;fetchAll(); $STH = $this-&gt;database-&gt;prepare('SELECT * FROM payouts WHERE user = :userid '); $STH-&gt;execute(array(':userid' =&gt; $user)); $payouts = $STH-&gt;fetchAll(); </code></pre>
 

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