Page 1 of 1

php mysql querys

Posted: Thu Oct 20, 2011 3:28 pm
by bazconnolly
Hi All

I am a bit stuck with what is probably very simple.

I have a script to query a mysql property database, I need to know how to use conditions within the record set. Here is my code:

Code: Select all

  <?php 
 


$query = ("SELECT * FROM property ORDER BY RAND() LIMIT 10")
or die(mysql_error());

$result = mysql_query($query,$conn);

while($row = mysql_fetch_array($result)) {
?> 

<div class="res-holder">

<div class="res-img-border">
<div class="res-img"><a href="/propertydetails.php?PID=<?php echo$row['PID'];?>"><img src="<?php echo $row['MainImg'] ; ?>" width="130" height="90" border="0"/></a></div>
</div>
<div class="res-price">£ <?php echo $row['Price']; ?></div>

<div class="res-type"><?php echo $row['Beds']; ?> Bed <?php echo $row['Type']; ?></div>

<div class="res-loc"><?php echo $row['L3Name']; ?></div>



</div><!-- res-holder END -->

<?php } ?>
What I need to do is when the a record is returned that has a null value for the 'L3Name field' . then the script should show the L2Name field instead for example:

Code: Select all

<div class="res-loc"> if  { $row['L3Name'] = null }  echo $row['L2Name'] else { echo ['L3Name'] } </div>
. I know this code is wrong but can anyone show me how to right this line of code,

Any help would be very much appreciated

thanks

Baz

Re: php mysql querys

Posted: Thu Oct 20, 2011 4:11 pm
by Celauran
You're using the assignment operator (=) instead of the comparison operator(==).

Code: Select all

echo (!empty($row['L3Name'])) ? $row['L3Name'] : $row['L2Name'];