Thread: shared thinking
View Single Post
Old 11-16-2004, 06:21 PM   #4 (permalink)
DavH27
PHP Pilgrim
 
DavH27's Avatar
 
Join Date: Aug 2004
Location: London
Posts: 170
DavH27 is on a distinguished road
A non-flat database would be alot easier! Falsepride you don't half have to do things the long way around!

Here's how I would do it...

I'd have 2 tables in my db. The first is 'news' with 5 fields:
1 nID (not auto-inc but the news saving code would count the rows in the news table and add 1 to it so that the same number can be used in the second table, 'comments')
2 title
3 body
4 author
5 when

Now depending on if I have a secondary author that doesn't have complete permissions, I'd have an extra field titled 'verify' which would be either 0 for not being shown at all or 'deleted', a 1 for displaying it or a 3 for an article submitted by one of my news reporters that needs an admin's verification.

The second table would be titled 'comments' and would have 5 fields much like the news table:
1 cID (this would be what the nID is as explained in table 1)
2 uc (standing for unique comment. This id would be to distinguish between the other comments for each news item. Would also be used to dynamically populate anchor links so that people can specificall;y hot link a URL directly to this comment. This technique is used alot in blog systems with a name such as 'link to this entry')
3 body
4 author
5 when

The page with the news on would be a loop that would go through the news table and pull the news off it. In the bottom corner would be a dynamically created figure from the amount of comments for that news, '(6 comment/s)'.

As for editing the news, I'd have a session check in the code that check if the 'admin' is logged in. If he is then it will display the 'edit' and 'delete' links beside each news item. The URLs for these would have the url with a GET variable appended on which would be the nID as well as the variable action=edit. The page that loads up would take this nID, look it up in the db and populate the news edit fields with what they return.

When the save button is clicked, the news text would simply replace the news item in the database.

If the 'delete' link was clicked then the page that loads up would also have the same GET variable nID but the 'action' would be action=delete and it would ask you to confirm the deletion. When the 'Yes' is clicked then the same page would load with the same GET variable accept a new variable would be introduced confirm=1 and then the page would just either run the SQL DELETE code or just set the 'verify' to 0 as explained way up there ^^.


Now....it is half past 2 in the morning. I'm tired and feeling nasty so sorry if this made little sense but you should get the gist.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a

Last edited by DavH27; 11-16-2004 at 06:24 PM. Reason: 0 instead of 3
DavH27 is offline   Reply With Quote