pemula Posted January 10, 2012 Share Posted January 10, 2012 Hi all, I have table, named: tb_event (id, f_date, f_title, f_image, f_status) How to manage, while if 'f_status' from all records NOT EQUAL to 'Published' then show ABCDE Note: on tb_event should be only the latest record (1 record only) that will be shown/published I have code: <? $qry = mysql_query( "SELECT * FROM tb_event WHERE f_status = 'Published'") or die(mysql_error()); while($res = mysql_fetch_array($qry)) { if ($res[f_status] = "Published") { echo ' <img src="images/uploads/'.$res[f_image].'" border="0" /> '; } else { echo ' ABCDE '; } } ?> The result is 'ABCDE' not shown while f_image (all records) is OFF Please help me.. thx Link to comment https://forums.phpfreaks.com/topic/254695-showing-content/ Share on other sites More sharing options...
MasterACE14 Posted January 10, 2012 Share Posted January 10, 2012 <?php // it's best practice not to use short tags $qry = mysql_query( "SELECT * FROM tb_event ORDER BY `f_date` DESC LIMIT 1") or die(mysql_error()); // order by `f_date` or `id` in descending order, limit to 1 result while($res = mysql_fetch_array($qry)) { if ($res[f_status] == "Published") { // changed '=' to '==', so it compares rather than assigns echo ' <img src="images/uploads/'.$res[f_image].'" border="0" /> '; } else { echo ' ABCDE '; } } ?> Link to comment https://forums.phpfreaks.com/topic/254695-showing-content/#findComment-1305993 Share on other sites More sharing options...
pemula Posted January 12, 2012 Author Share Posted January 12, 2012 tq sir... it works Link to comment https://forums.phpfreaks.com/topic/254695-showing-content/#findComment-1306770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.