Jump to content

showing content


pemula

Recommended Posts

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.