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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.