[PHP] If ... then conditional with an OR clause

Associate
Joined
29 May 2003
Posts
2,038
Location
Cambridge
I've got a simple data table on my page that draws values from a MySQL database and everything is working just fine except on one line I can't get an OR clause to work correctly - I'm pretty sure it's something minor, but in my n00bness I can't see it ...

Code:
<?php if ($row_rsLangtonprice['price'] == "SOLD") || ($row_rsLangtonprice['price'] == "RESERVED") {echo '<span class="redtext">'. $row_rsLangtonprice['price'].'</span>';} else {echo $row_rsLangtonprice['price'];} ?>

All I am wanting to do is echo the value - other CSS styles take care of the type size, line height etc - but to wrap a <span> tag around the output if the database value is "SOLD" or "RESERVED". Just testing for one eventuality worked fine, adding the OR has introduced the problem. Viewing it in a browser gives the error:

Parse error: syntax error, unexpected T_BOOLEAN_OR in C:\Apache2\htdocs\ehnew\test.php on line 163

Any ideas? Be gentle with a beginner :D ...
 
try this

Code:
<?php 
	if(($row_rsLangtonprice['price'] == "SOLD") || ($row_rsLangtonprice['price'] == "RESERVED")) 
	{
		echo '<span class="redtext">'. $row_rsLangtonprice['price'].'</span>';
	} else {
		echo $row_rsLangtonprice['price'];
	} 
		
?>
 
that would have been my guess too :)

always make sure you bracket your whole expression :)

oh and of course each individual expression within the main brackets :)
 
Back
Top Bottom