×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

if else inside echo $row?
2

if else inside echo $row?

if else inside echo $row?

(OP)
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

RE: if else inside echo $row?

Hi

I use an array of human readable strings and pick from it by index :

CODE --> php -a

php > 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

RE: if else inside echo $row?

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

CODE

$texts[0] = 'No';
$texts[1] = 'Yes';
<?php 
    
    while($row = mysql_fetch_array($result))
  {  
  
 ?>
       
 <tr>
     <td><?php echo $texts[$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 
  
  }
  ?>  

----------------------------------
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

RE: if else inside echo $row?

(OP)
Oh wow that's so simple! I like simple! :) This one is good.

Thanks guys!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close