Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best approach to list a user's recent activities in PHP/MySQL?
    primarykey
    data
    text
    <p>I want to list the recent activities of a user on my site without doing too many queries. I have a table where I list all the things the user did with the date.</p> <pre><code>page_id - reference_id - reference_table - created_at - updated_at </code></pre> <p>The <code>reference_id</code> is the ID I need to search for in the reference_table (example: comments). If I would do a <code>SELECT</code> on my activity table I would then have to query:</p> <pre><code>SELECT * FROM reference_table where id = reference_id LIMIT 1 </code></pre> <p>An activity can be a comment, a page update or a subscription. Depending which one it is, I need to fetch different data from other tables in my database</p> <p>For example if it is a comment, I need to fetch the author's name, the comment, if it is a reply I need to fetch the orignal comment username, etc.</p> <p>I've looked into UNION keyword to union all my tables but I'm getting the error</p> <blockquote> <p>1222 - The used SELECT statements have a different number of columns</p> </blockquote> <p>and it seems rather complicated to make it work because the amount of columns has to match and none of my table has the same amount of tables and I'm not to fond of create column for the fun of it.</p> <p>I've also looked into the CASE statement which also requires the amount of columns to match if I remember correctly (I could be wrong for this one though).</p> <p>Does anyone has an idea of how I could list the recent activities of a user without doing too many queries?</p> <p>I am using PHP and MySQL.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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