Re: news and article posts in one table
| From: | Tamara Temple | Date: | Sat, 26 Nov 2011 19:26:49 +0000 |
| Subject: | Re: news and article posts in one table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-315829@lists.php.net to get a copy of this message | ||
muad shibani <muad.shibani@gmail.com> wrote:
> i wanna to create one table that contains both news and articles posts,
> they have similar columns like id, title, content, and date but they are
> differ in one column = the source of news or article post
> article has writers that have permanent names and pictures obtained from
> another table called writers that supposed to be left joined with the news
> table, while news posts simply have a source as text like AFP
> or Reuters and so one.
>
> How I can solve this ?
How you store things in tables can sometimes get a little tricky. One
way to approach this is with normalized tables and using joins in your
query like you are doing. To make this work, in your main entries table,
have a field that indicates what the entry type is. If you are doing one
select that gets both articles and news stories, having that extra field
can help you distinguish what type it is, and which fields contain data
in each record.
(cf: Wordpress wp_posts table for an example of how this is done. They
store posts, pages, and attachments in a single table this way. I can't
say if this is a better arrangement than keeping them in separate
tables.)