Hi guys,
Need a little help, I’m working on a blog and I need help with something. I’m still learning PHP and mySQL, so please forgive my ignorance lol.
Basically I have two database tables one which contains all the articles, date, title and so on and the other contains all the comments.
I have it so that I can comment on articles, this works fine. But on my index I want to display how many comments have been made in each article. I have it so on the article page it displays how many comments have been made and it’s probably something similar.
Here is the code I have for my recordsets etc: -
mysql_select_db($database_cr_blog, $cr_blog);
$query_entry = "SELECT * FROM cr_entry ORDER BY id DESC";
$query_limit_entry = sprintf("%s LIMIT %d, %d", $query_entry, $startRow_entry, $maxRows_entry);
$entry = mysql_query($query_limit_entry, $cr_blog) or die(mysql_error());
$row_entry = mysql_fetch_assoc($entry);
if (isset($_GET['totalRows_entry'])) {
$totalRows_entry = $_GET['totalRows_entry'];
} else {
$all_entry = mysql_query($query_entry, $cr_blog) or die(mysql_error());
$totalRows_entry = mysql_num_rows($all_entry);
}
$totalPages_entry = ceil($totalRows_entry/$maxRows_entry)-1;
$colname_comments = "-1";
if (isset($_GET['id'])) {
$colname_comments = $_GET['id'];
}
mysql_select_db($database_cr_blog, $cr_blog);
$query_comments = sprintf("SELECT * FROM cr_entry_comments WHERE entry_id", GetSQLValueString($colname_comments, "int"));
$comments = mysql_query($query_comments, $cr_blog) or die(mysql_error());
$row_comments = mysql_fetch_assoc($comments);
$totalRows_comments = mysql_num_rows($comments);
I think that’s it, sorry I’m using dreamweaver for most of this, I’m trying to ween myself off it! lol.
I’m thinking that I have to make it so that the entry_id in the comments matches the id in cr_entry.
Something like this: -
"SELECT * FROM cr_entry_comments WHERE entry_id = FROM cr_entry WHERE id";
Now, I know that’s not it, but if someone could help me figure it out I will be very grateful,
Thanks in advanced!