I'm having problems getting my simple if-statement to work inside a PHP while loop. This is my code:
$p=mysql_query("SELECT * FROM forum_posts WHERE forum_id='$cid' AND topic_id='$id' AND post_deleted='0' ORDER BY post_time ASC LIMIT $offset, $rowsperpage");
while($post=mysql_fetch_assoc($p)){
$userpost=$user->getUserData($post['userid']);
if($userpost['specialmembership'] == 1){
$pioneer = "True";
}
echo $userpost['username'];
echo $pioneer;
}
So, in the above example I have two different users. They are named user1 and user2.
- User1 has specialmembership = 0
- User2 has specialmembership = 1
The above code will output the following (the while loop in this example is getting looped 4 times):
It will output:
user1
user2
true
user1
true
user2
true
The problem is here, that the script is printing out true on user1 in the third loop. User1 shouldn't be set to true, only user2 should that, since he has specialmembership = 1;
What is wrong here?
$pioneerto false as the first line inside your while loop.