dachshund Posted May 21, 2008 Share Posted May 21, 2008 Im trying to work out how to only include the 'image' part of this code <?php $sql="SELECT * FROM entries ORDER BY id DESC LIMIT 10"; $result=mysql_query($sql); ?> <?php while($rows=mysql_fetch_array($result)){ $date = date('d/m', strtotime($rows['date'])); ?> <table width="100%" border="0" align="center" cellpadding="5" class="bottomborder"> <tr> <td align="left" bgcolor="#FFFFFF" class="contentmaintitle" valign="top"> <? echo $rows['title']; ?> </td> <td align="right" bgcolor="#FFFFFF" class="wordsby" valign="top"> <? echo $date; ?> </td> </tr> <tr> <td align="left" bgcolor="#FFFFFF" colspan="3" valign="top"> <img src="<? echo $rows['image']; ?>" /> </td> </tr> <tr> <td align="left" colspan="3" valign="top"> <? echo $rows['object']; ?> </td> </tr> <tr> <td align="left" bgcolor="#FFFFFF" colspan="3" class="maincontent"> <? echo $rows['post']; ?> </td> </tr> </table> <?php } mysql_close(); ?> if there's actually an entry in there. Otherwise I want it not to include it at all. Anyone know how to do that? Link to comment https://forums.phpfreaks.com/topic/106554-only-echo-if-entry-exists/ Share on other sites More sharing options...
corbin Posted May 21, 2008 Share Posted May 21, 2008 if(mysql_num_rows($result) > 0) { //there's rows from the DB http://php.net/mysql_num_rows Link to comment https://forums.phpfreaks.com/topic/106554-only-echo-if-entry-exists/#findComment-546225 Share on other sites More sharing options...
redarrow Posted May 21, 2008 Share Posted May 21, 2008 code eample......... also use mysql_num_rows// dam your all fast... <?php $img="<img src='http://www.google.co.uk/intl/en_uk/images/logo.gif' />"; $img_empty=""; if(empty($img)){ echo"no image sorry!"; }else{ echo $img; } ?> Link to comment https://forums.phpfreaks.com/topic/106554-only-echo-if-entry-exists/#findComment-546229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.