Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/67596-im-trying-to-make-a-blog/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.