xseg Posted September 2, 2007 Share Posted September 2, 2007 Hello, I'm working on creating a blog for myself. I got the basic system down. The problem is i'm trying to make a comment system. I have two tables. One that stores the blog posts, and another that has blog comments. Each blog post has an id, then in the blog_comments table there is an ID field to put the id of the blog post it belongs to. I have an array on my index.php so it outputs all the posts nicely. The problem is I don't know how to integrate mysql_num_rows into that array so I can have the comment count. Hopefully I didn't confuse you. Here is what I got: <?php include("head.php"); ?> <? //connect to mysql mysql_connect("localhost","benwara_kayak",""); //select which database mysql_select_db("benwara_kayak"); //select the table $entry = mysql_query("select * from blog order by id desc"); //grab all the content while($r=mysql_fetch_array($entry)) { $id=$r["id"]; $author=$r["author"]; $date=$r["date"]; $title=$r["title"]; $post=$r["post"]; ?> <?php echo "<h1>" . $title . "</h1>" ?> <?php echo $post ?> <?php echo '<small>Posted by ' . $author . ' on ' . $date . ' | no comment system at this time</small>'; } ?> <?php include("footer.php"); ?> Just to clarify, what I am trying to do is add a $var that will count the number of comments that have the same id as the post for the table called blog_comments , so that way I can add it in there. Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 2, 2007 Share Posted September 2, 2007 $sql = "select blog.*, SUM(comments.*) from blog, comments WHERE blog.id = comments.blogID order by blog.id desc"; You'll have to change the column and table names to match. Quote Link to comment Share on other sites More sharing options...
xseg Posted September 2, 2007 Author Share Posted September 2, 2007 Thanks for the fast reply! I'm new to php, could you explain that a little please? Quote Link to comment Share on other sites More sharing options...
xseg Posted September 2, 2007 Author Share Posted September 2, 2007 would i have to put that in the array? with the other $vars that pull the stuff from the table? Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 2, 2007 Share Posted September 2, 2007 Well that is SQL, not PHP. What is there to explain? That is your SQL string, replace the one you have with it. Look up the functions you don't know before asking about them at least And if you're that new, maybe a smaller project would be a good place to start. If you're making something complex like a blog, you'll need to learn about security (SQL and email header injection) and other things. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.