PHP: binary 0 displaying as 1

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
philanderson888
Forum Newbie
Posts: 1
Joined: Sat May 31, 2014 4:18 pm

PHP: binary 0 displaying as 1

Post by philanderson888 »

Hi

Why is this code returning Yes every time regardless of the value of 'upat3' which could be integer 1 or 0 in my database; regardless if it's a 1 or 0 the PHP code is outputting a Yes and never a No. This is on a MYSQL Linux server by the way.

Code: Select all

	$yesno = (int)$row['upat3'];
		if ($yesno = 1) { echo '<td>Yes</td>'; }
		if ($yesno = 0) { echo '<td>No</td>'; }
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP: binary 0 displaying as 1

Post by Weirdan »

That's because you're using '=' operator (assignment) instead of '==' operator (equality test).
Post Reply