Page 1 of 1

Not sure how to make this PHP/Ajax feature

Posted: Wed Jul 23, 2008 3:17 pm
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?

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

Posted: Wed Jul 23, 2008 5:31 pm
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);
 

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

Posted: Thu Jul 24, 2008 2:21 pm
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...