Jump to content

Archived

This topic is now archived and is closed to further replies.

liquidprozak

Formatting Boolean Output

Recommended Posts

I am having a heck of time getting my Admin portion of my site to list a record, which is a Boolean type, as  Yes or No, not as 1 or 0.  I am listing data from MySQL that shows all users who are registered, but under the Admin column, I would like it to say Yes or No, not 1 or 0.  Coldfusion has a nifty command called YesNoFormat(), but alas, it appears there is nothing remotely simple to do this in PHP.  Any help would be greatly appreciated.

Thank you

Share this post


Link to post
Share on other sites
Without seeing you code, it's a little hard to tell you what you are doing wrong.

Try something like this:
[code]<?php
$yn = 1;
echo ($yn)?'Yes':'No';
?>[/code]

Ken

Share this post


Link to post
Share on other sites
(Ken beated me) if nothing else:

[code]
<?php
$blah = 0;

echo ($blah) ? "yes" : "no";

// or make a function
function YesNoFormat($x) {
  return ($x)? "yes" : "no";
}

echo YesNoFormat($blah);
?>  [/code]

Share this post


Link to post
Share on other sites
Or you can do it the sql code

SELECT CASE WHEN admin=1 THEN 'Yes' ELSE 'No' END AS admin

Share this post


Link to post
Share on other sites
Nice....the data is being pulled from a MySQL database, so it looks to me like the SQL code would work for my needs.  I can't thank everyone enough.  I was ready to start pulling my hair out.

Share this post


Link to post
Share on other sites
Well, here is a piece from my code.

<div id="content"><!-- InstanceBeginEditable name="TopContent" -->
    <div class="feature">
      <h3>Below is a listing of all news records in the database.</h3>
      <p><a href="add.php">Add a new News Record</a></p>
      <p>&nbsp;  </p>
      <table border="1" cellpadding="1" cellspacing="1">
        <tr>
          <th>Date Added</th>
          <th>Header</th>
          <th>News</th>
          <th>Online</th>
        </tr>
        <?php do { ?>
          <tr>
            <td><a href="edit.php?NewsID=<?php echo $row_rsNews['NewsID']; ?>"><?php echo $row_rsNews['DateAdded']; ?></a></td>
            <td><?php echo $row_rsNews['Header']; ?></td>
            <td><?php echo $row_rsNews['News']; ?></td>
          [color=red][/color]<td><?php echo $row_rsNews['Online']; ?></td>        </tr> [color=red]<-This is where I want to display Yes or no[/color]

          <?php } while ($row_rsNews = mysql_fetch_assoc($rsNews)); ?>
      </table>
    </div>

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.