Drawbacks to Creating Large Numbers of Tables in the Same Database If you have many files in a directory, open, close, and create operations will be slow. If you execute SELECT statements on many different tables, there will be a little overhead when the table cache is full, because for every table that has to be opened, another must be closed. |
#If table exists, start: function show_thread($table, $parent, $trail=array('')) { #Retrieve all comments with a certain parent ID, newest first $comment_query= mysql_query('SELECT ID, date, user, title FROM '.$table.' WHERE parent='.$parent.' ORDER BY date DESC'); $i= 1; while ($com= mysql_fetch_array($comment_query)) { #The tricky part. The last element of the array $trail is #assigned 1 if there are more remaining rows in the last #query, or 0 if it is the last row $trail[count($trail)-1]= ($i==mysql_num_rows($comquery))? 0: 1; #Each of the first n-1 elements of $trail is printed out as #the relevant graphic, trail0.gif or trail1.gif respevtively. for ($x= 0; $x<count($trail)-1; $x++) print '<IMG SRC=trail'.$trail[$x].'.gif WIDTH=16 HEIGHT=18 ALIGN=top>'; #Print the n-th element of $trail as the relevant graphic, #end0.gif or end.gif, then the comment link print '<IMG SRC=end'.$trail[$x].'.gif WIDTH=16 HEIGHT=18 ALIGN=top> print '<A HREF=display_comment.php?id=ARTICLE_ID&cid=COMMENT_ID>'.htmlspecialchars($com['title']).'</A> print '('.$com['date'].', '.$com['user'].')<BR>'; #Add a new element to the end of the array $trail $trail[]= ''; #Call this function again with the above result as the parent show_thread($table, $com[0], $trail); #Subtract the last element of the array $trail array_pop($trail); $i++; } } #Call the function with 0 as the parent comment thread(TABLE_NAME, 0); |
CREATE TABLE IF NOT EXISTS...
can save you a lot of hassle.function kill_branch($table, $parent) { #Kill the given posting mysql_query('DELETE FROM '.$table.' WHERE ID="'.$parent.'"'); $findquery= mysql_query('SELECT ID FROM '.$table.' WHERE parent="'.$parent.'"'); #Call the same function for all its "children" while ($find= mysql_fetch_array($findquery)) kill_branch($table, $find['ID']); } kill_branch(TABLE_NAME, COMMENT_ID); |
DELETE FROM comments WHERE ID=COMMENT_ID OR parent_ID=COMMENT_ID
and be reasonably safe. Eventually, we realised that