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. Quote Link to comment 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. Quote Link to comment 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` Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.