Page 1 of 1

PHP: binary 0 displaying as 1

Posted: Sat May 31, 2014 4:24 pm
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>'; }

Re: PHP: binary 0 displaying as 1

Posted: Sat May 31, 2014 5:01 pm
by Weirdan
That's because you're using '=' operator (assignment) instead of '==' operator (equality test).