liquidprozak Posted October 26, 2006 Share Posted October 26, 2006 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 Link to comment https://forums.phpfreaks.com/topic/25237-formatting-boolean-output/ Share on other sites More sharing options...
kenrbnsn Posted October 26, 2006 Share Posted October 26, 2006 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 Link to comment https://forums.phpfreaks.com/topic/25237-formatting-boolean-output/#findComment-115087 Share on other sites More sharing options...
.josh Posted October 26, 2006 Share Posted October 26, 2006 (Ken beated me) if nothing else:[code]<?php$blah = 0;echo ($blah) ? "yes" : "no";// or make a functionfunction YesNoFormat($x) { return ($x)? "yes" : "no";} echo YesNoFormat($blah);?> [/code] Link to comment https://forums.phpfreaks.com/topic/25237-formatting-boolean-output/#findComment-115089 Share on other sites More sharing options...
Barand Posted October 26, 2006 Share Posted October 26, 2006 Or you can do it the sql codeSELECT CASE WHEN admin=1 THEN 'Yes' ELSE 'No' END AS admin Link to comment https://forums.phpfreaks.com/topic/25237-formatting-boolean-output/#findComment-115092 Share on other sites More sharing options...
liquidprozak Posted October 26, 2006 Author Share Posted October 26, 2006 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. Link to comment https://forums.phpfreaks.com/topic/25237-formatting-boolean-output/#findComment-115096 Share on other sites More sharing options...
liquidprozak Posted October 26, 2006 Author Share Posted October 26, 2006 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> </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> Link to comment https://forums.phpfreaks.com/topic/25237-formatting-boolean-output/#findComment-115102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.