dsp77 Posted October 19, 2009 Share Posted October 19, 2009 Hello, I have this in the table: "value" type int 0 to represent false and 1 to represent true. everything works great in display to the user end it sees 0 or 1 i want to replace the 0 to display No and 1 to display Yes or a picture. please advise me how can i make this work. Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/ Share on other sites More sharing options...
Bricktop Posted October 19, 2009 Share Posted October 19, 2009 Hi dsp77, There are a number of ways, but a simple if statement like this should do the trick: $x = (row['somerow'] == 0) ? "No": "Yes"; echo $x; Hope this helps. Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/#findComment-939594 Share on other sites More sharing options...
JAY6390 Posted October 19, 2009 Share Posted October 19, 2009 Just use the if statement in your query IF(`value` = 'Yes', 1, 0) as `value2` Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/#findComment-939596 Share on other sites More sharing options...
dsp77 Posted October 19, 2009 Author Share Posted October 19, 2009 well this is my code: <?php require_once('config.php'); $result=mysql_query("select * from table order by id asc"); ?> <?php while($row=mysql_fetch_assoc($result)){ ?> <table class="table_i" cellpadding="1" cellspacing="1" id="resultTable"> <thead> <tr> <th bgcolor="orange"><strong>ID</strong></th> <th bgcolor="orange"><strong>Name</strong></th> <th bgcolor="orange"><strong>Value</strong></th> </tr> </thead> </table> <?php while($row=mysql_fetch_assoc($result)){ ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['value']; ?></td> </tr> <?php } ?> if i use $x = (row['somerow'] == 0) ? "No": "Yes"; echo $x; i get Parse error: syntax error, unexpected '[' and if i use the query i get a boolean error Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/#findComment-939604 Share on other sites More sharing options...
JAY6390 Posted October 19, 2009 Share Posted October 19, 2009 OOps posted the values the wrong way round select `id`, `name`, IF(`value`= 1, 'Yes', 'No') as `value` from table order by id asc Also with the php code that gave you an error you need to put a $ before row Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/#findComment-939605 Share on other sites More sharing options...
Bricktop Posted October 19, 2009 Share Posted October 19, 2009 Whoops, sorry dsp77, small typo I forgot the $, thanks JAY6390 Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/#findComment-939607 Share on other sites More sharing options...
dsp77 Posted October 19, 2009 Author Share Posted October 19, 2009 thank you so much it worked, i saw that missing $ to a bit late:P Link to comment https://forums.phpfreaks.com/topic/178212-solved-transform-value-0-in-no-and-1-in-yes-help-needed/#findComment-939609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.