Trouble Retrieving a count from a MySQL db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Trouble Retrieving a count from a MySQL db

Post 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]
slippyaah
Forum Newbie
Posts: 11
Joined: Wed Jan 14, 2004 5:00 am

Post by slippyaah »

by the way, I'm getting the following error in the browser:

Parse error: syntax error, unexpected '['
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

&lt;?=&#1111;'$comment_row']?&gt;
is the problem. Remove the brackets and the quotes.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
Post Reply