Search code examples
phparraysserializationforum

PHP Forum - Read/Unread Posts


After much pondering, I thought of a way to tackle this.

Posts Table:
post_id int, primary key, auto increment
post_content text
has_read text

In has_red would be a serialized array that looks something like this:

<?php

$has_read = array(
    '1' => 'true', // 1 = User ID
    '2' => 'false', // 2 = User Id
    '3' => 'false', // 3 = User Id
);

?>

I can't think of any issues I'd have with this, can you guys?

Thanks!


Solution

  • Don't do that. Storing a serialized array as text is almost always a sign of very bad design. You can't write queries on serialized data (easily).

    Instead you should be making another table, that relates user's to the posts they've read.