esoteric Posted September 16, 2011 Share Posted September 16, 2011 Hi, i cant seem to get something working, should be simple but its not working for me. I just need to only display a table if a variable in my table = a certain value. The column in the table is called 'option1_available' and if its value is set to 'Y' i want it to display a table. Appreciate any help, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/247303-display-table-if-variable-is-set/ Share on other sites More sharing options...
predator12341 Posted September 16, 2011 Share Posted September 16, 2011 you just need to get that variable before you "draw" the table then you can just encase it in an if statement. Example: <? if($var) { ?> <table> <tr> <td></td> <td></td> <td></td> </tr> </table> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/247303-display-table-if-variable-is-set/#findComment-1270077 Share on other sites More sharing options...
esoteric Posted September 16, 2011 Author Share Posted September 16, 2011 I tried $op1_av = ("SELECT option3_available FROM $tbl WHERE title='$product'") or die ("Cannot find purchase options"); if ( $op1_av == 'Y' ) { ... }else echo "Nope, not working "; but it just echo the else statement instead, even if the variable in the table is set to Y Quote Link to comment https://forums.phpfreaks.com/topic/247303-display-table-if-variable-is-set/#findComment-1270089 Share on other sites More sharing options...
Pikachu2000 Posted September 16, 2011 Share Posted September 16, 2011 You would need to actually execute the query, then fetch the value from the result resource for the comparison to be valid. Quote Link to comment https://forums.phpfreaks.com/topic/247303-display-table-if-variable-is-set/#findComment-1270090 Share on other sites More sharing options...
xyph Posted September 16, 2011 Share Posted September 16, 2011 Why not only select data where 'option1_available' = 'Y' ? SELECT `thisColumn`, `thatColumn` FROM `yourTable` WHERE `option1_available` = 'Y' Quote Link to comment https://forums.phpfreaks.com/topic/247303-display-table-if-variable-is-set/#findComment-1270092 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.