Re: MySQL news database structure
| From: | Miguel Cruz | Date: | Fri, 05 Jul 2002 07:31:15 +0000 |
| Subject: | Re: MySQL news database structure | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-105586@lists.php.net to get a copy of this message | ||
On Fri, 5 Jul 2002, Pag wrote:
> Table 1 (news)
> ------------------------------
> ID
> Date
> Author
> Title
> News Text
>
> Table 2 (comments)
> --------------------------------
> ID
> News ID (to which news it belongs to)
> Date
> Author
> Comment text
>
> Everytime i want to show the comments on some news article, i have to do
> a query to the whole table 2, selecting the entries that have the "news
> ID" equal to the ID of the news i want. It works but is this ok for
> when i have hundreds of news/comments later on? Wont it slow down
> things? Is there an easier way for this news/comments script?
You're doing it the right way. Make sure that news ID is a key in the
comments table:
alter table contents add key(news_id);
and then this query will be VERY fast. That's the whole point.
If your authors are drawn from a limited pool (i.e., registered users)
then you probably want to have a table for them too rather than storing
any of the author's information inside the comments table.
miguel