Page 1 of 1

Trouble Retrieving a count from a MySQL db

Posted: Sun Jan 02, 2005 6:21 am
by slippyaah
Just trying to retrieve a count from the database I'm linked to with regards to comments made on a news article. It so far displays a "view comments" link if there are any comments on that article in question but I'm trying to include the number of comments in that link too. For example; view comments[5]

this is the code I have so far:

Code: Select all

// if there are then display the "view comments" link.
			if (!mysql_num_rows($comments) == 0) 
			{
				// The javascript allows the "view comments" to be toggled on and off by clicking the link
				$comment_result = mysql_query ($comments);
				$comment_row = mysql_fetch_row($comment_result);
				?>
				| <a href="#" onclick="toggle('viewcomment<?=$row['entryID']?>')">View comments<?=['$comment_row']?>"</a>
				<div id="viewcomment<?=$row['entryID']?>" style="display: none;">
Can anyone point out what else i need or where I might have gone wrong in trying to perform this?

Thanks


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Sun Jan 02, 2005 6:23 am
by slippyaah
by the way, I'm getting the following error in the browser:

Parse error: syntax error, unexpected '['

Posted: Sun Jan 02, 2005 6:51 am
by feyd

Code: Select all

&lt;?=&#1111;'$comment_row']?&gt;
is the problem. Remove the brackets and the quotes.

Posted: Sun Jan 02, 2005 10:43 am
by Bill H
This is a little strange,

Code: Select all

<?php
if (!mysql_num_rows($comments) == 0) 
?>
why would you not just do:

Code: Select all

<?php
if (mysql_num_rows($comments) != 0) 
//or
if (mysql_num_rows($comments) > 0) 
?>
Also, these two lines seem incompatible

Code: Select all

<?php
if (!mysql_num_rows($comments) == 0) 
//and
$comment_result = mysql_query ($comments);
?>
The $comment var is a resousce result in the first instance and a string in the second?
It's one or the other, but can't really be both.