Hi, well as the title says, I'm programming a HN clone. I choose PHP because is more simple to find a hosting which provides us PHP.<p>And I have some questions, the first is about HN comments, in its structure a comment is an item. I'm using MySQL, and my table 'items' can store comments too. My question is: HN has a limit deep in comments? Because is complicate get comments using recursivity.<p>That's the reason because I prefer use SQL and a limit of comments.<p>I have no time to finish quickly this project, but I'll try to do it fast.<p>There are lots of broken links, only works the login/signup and an item views.<p>URL: http://news.sourcezilla.com<p>Thanks in advance.
I am too.<p>I've found a few methods for rendering trees from SQL, and I find that Stack Overflow is your friend here. The method that seems to work best to me is closure tables - although it's complex, you'll find implementations available. Essentially you need two tables, one for items (in my implementation, which is not online), this is currently only storing name, date, comment, etc - essentially, find the depth of the parent and ++) and another table separately to handle the relationships and build the tree.<p>If you want to limit comment depth, one way to do that is to keep track of the depth of comments by incrementing a value for each comment (the root comment has depth 0, replies have depth 1, replies to replies have depth 2, etc.) Although this method may lead to anomalies in the data.<p>You shouldn't need extremely complex recursion, however, as far as I know, apart from self-joins in the database itself. Before using closure tables, I was using a basic method where every item stored its own parent, and a reference to the root post, and this worked except getting an entire tree took multiple queries. (and to be fair, I am not exactly a rocket scientist when it comes to SQL)<p>Also - ignore whoever downthread tries to criticize you for using PHP. This is about as basic a CRUD app as you can make, as long as you're not doing anything crazy like using the mysql_* functions and concatenating strings, then it mostly shouldn't matter.
You need to do self joins. You can have one comments table but there can be parent_id for each comment.<p><a href="http://stackoverflow.com/questions/3362038/what-is-self-join-and-when-would-you-use-it" rel="nofollow">http://stackoverflow.com/questions/3362038/what-is-self-join...</a> this might help.