Not sure how to make this PHP/Ajax feature

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mephistoo
Forum Newbie
Posts: 6
Joined: Sat Jul 19, 2008 6:56 pm

Not sure how to make this PHP/Ajax feature

Post by mephistoo »

Hi. I am trying to implement something like the comment system on digg, where comment can not only be posted, but also rated by other people. My question is more about the structure, or approach of the code.
How can I design this kind of system?

What would be the best approach to take here? Every comment should have an ID i suppose... I also looked with firebug into Digg code, and the 'bury' image has HTML code:
<img height="18" width="18" alt="" id="bury-c17145374" src="/img/c-bury.png"/>
I was expecting code like onClick="voteUp(id=c17...)", or something similar. What kind of approach is that?
manixrock
Forum Commoner
Posts: 45
Joined: Sun Jul 20, 2008 6:38 pm

Re: Not sure how to make this PHP/Ajax feature

Post by manixrock »

Digg style buttons are <a> tags with onclick events on them which can be seen with firebug (on the front page of digg at least, where did you check?).

However click events can also be added with javascript, and it would not show up at all in firebug.

Code: Select all

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ // For Firefox
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ // For Internet Explorer
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 }
}
addEvent(element, 'click', someFunction);
 
mephistoo
Forum Newbie
Posts: 6
Joined: Sat Jul 19, 2008 6:56 pm

Re: Not sure how to make this PHP/Ajax feature

Post by mephistoo »

if you go inside an article, where you see all comments on the article, each digg up or digg down is exactly what i posted. But if you can add javascript events on things like that, then that explains it.

so i am thinking that i should have each comment have an id in the database, and then the database would look like

commentID, IP Address, Vote

where vote is -1 for bad, 1 for good comment. Then if a person clicks something, i could do an insert or an update, depending on if the entry exists. To calculate the total net number of comment thumbs (up -down), i can just do COUNT calls WHERE Vote=-1 and Vote=1 and subtract. That seems reasonable to me right now.

I wonder how I can generate the IDs now...
Post Reply