Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if else inside echo $row? 2

Status
Not open for further replies.

evil1966

MIS
Dec 2, 2013
57
US
I would like to display my boolean output on the webpage as "Yes" or "No instead of "1" or "0". Can I get a simple example on how/where that should go?

My current code
Code:
<?php 
    
    while($row = mysql_fetch_array($result))
  {  
  
 ?>
       
 <tr>
     <td><?php echo $row['aa']?></td>
     <td><?php echo $row['au']?></td>
     <td><?php echo $row['ad']?></td>
     <td><?php echo $row['fd']?></td>
     <td><?php echo $row['greeting']?></td>
     <td><?php echo $row['firstname']?></td>
     <td><a href=donorDetails.php?id=<?php echo $row['donor_id'];?>><?php echo $row['lastname']?></a></td>
     <td><?php echo $row['company']?></td>
     <td><?php echo $row['eMail']?></td>
     <td><?php echo preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $row['phone'])?></td>
     <td><?php echo preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $row['fax'])?></td>
     <td><?php echo $row['address1']?></td>
     <td><?php echo $row['city']?></td>
     <td><?php echo $row['state']?></td>
     <td><?php echo $row['zip']?></td>
     <td><?php echo $row['note']?></td>
  </tr>
  <?php 
  
  }
  ?>

The first 4 columns ('aa', 'au', 'ad' and 'fd' are boolean columns defaulting to 0.

Thanks
 
Hi

I use an array of human readable strings and pick from it by index :
Code:
[blue]php >[/blue] foreach ([0, 1, false, true] as $value) echo $value, ' means ', ['No', 'Yes'][$value], "\n";
0 means No
1 means Yes
 means No
1 means Yes


Feherke.
feherke.ga
 
The easiest way in my book. is using an array like this:

Code:
$texts[0] = 'No';
$texts[1] = 'Yes';
[COLOR=#888A85]<?php 
    
    while($row = mysql_fetch_array($result))
  {  
  
 ?>
       
 <tr>
     <td><?php echo [/color]$texts[$row['aa]][COLOR=#888A85]?></td>
     <td><?php echo $row['au']?></td>
     <td><?php echo $row['ad']?></td>
     <td><?php echo $row['fd']?></td>
     <td><?php echo $row['greeting']?></td>
     <td><?php echo $row['firstname']?></td>
     <td><a href=donorDetails.php?id=<?php echo $row['donor_id'];?>><?php echo $row['lastname']?></a></td>
     <td><?php echo $row['company']?></td>
     <td><?php echo $row['eMail']?></td>
     <td><?php echo preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $row['phone'])?></td>
     <td><?php echo preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $row['fax'])?></td>
     <td><?php echo $row['address1']?></td>
     <td><?php echo $row['city']?></td>
     <td><?php echo $row['state']?></td>
     <td><?php echo $row['zip']?></td>
     <td><?php echo $row['note']?></td>
  </tr>
  <?php 
  
  }
  ?> [/color]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Oh wow that's so simple! I like simple! :) This one is good.

Thanks guys!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top