I have code so that users can make comments on a page, they have a choice to have their name displayed or be anonymous. I want to order the comments by the date they were made, and display the name or 'anonymous poster' if they selected anonymous.
So I have this code which grabs everything into an array, but the if statement within the array is not working, in testing, when I select anonymous the page still displays the name of the user. What is the best way around this?
The following code is where I am stuck:
[php]
echo "<h3>Comments for this article:</h3>";
while($fetch=mysql_fetch_array($query)) {
$anonymous=$fetch['anonymous'];
if ($anonymous===true){
echo "<p>".$fetch['comment']."<br/><sub><b>Comment by: </b>'Anonymous Poster'</sub><hr /><p>";
}
else{
echo "<p>".$fetch['comment']."<br/><sub><b>Comment by: </b>".$fetch['userid']."</sub><hr /><p>";
}
}
Well, there's the issue that you're still using the MySQL extension.
But have you checked to see what $fetch['anonymous'] contains? Is it a boolean? Is it true? The type matters because of the comparison operator you're using.
Unfortunately, PHP can do that to ya ... generally at least a couple times a week, here.
/!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade!/!!!\ ereg() is deprecated --- don't use it!
dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket
Bookmarks