Hi There - I've written a script to display MySQL data for news items. I display them individually with a header and some text, surrounded by a border invoked by a css divider. Some of them have picture URLs as well. Here is the script:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Rolling Snowballs</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script src="SpryAssets/SpryAccordion.js" type="text/javascript"></script>
<link href="SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
//connect to the server
$connection = mysql_connect('localhost', 'guest','guest')
or die ('Unable to connect to MySQL server');
// echo 'Connected to Server<BR>';
// select database
mysql_select_db('rollsnow') or die ('Unable to connect to Database!<BR>');
// echo 'Connected to Database<BR>';
?>
<div class="wrapper">
<div class="bannertop"><br />
<img src="images/title.png" width=219 height=35 alt="logo"/>
</div>
<div class="navbg">
<div id="navcontainer">
<ul id="navlist">
<li><a href=index.php>Home</a></li>
<li><a href="about.php">About</a></li>
<li><a href="news.php">News</a></li>
<li><a href="productions.php">Productions</a></li>
<li><a href="press.php">Press</a> </li><li><a href="contact.htm">Contact</a></li>
</ul>
</div>
</div>
<div class="flashcontent">
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','800','height','150','title','browser','src','images/browser','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','images/browser' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="800" height="150" title="browser">
<param name="movie" value="images/browser.swf" />
<param name="quality" value="high" />
<embed src="images/browser.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="800" height="150"></embed>
</object></noscript>
</div>
<div class="content">
<div class="leftcolumn">
</div>
<div class="rightcolumn">
<?php
$query='SELECT UNIX_TIMESTAMP(n.date) AS date, n.title AS title, n.info AS info, g.thumb AS thumb FROM news AS n LEFT JOIN gallery AS g ON n.FK_gId = g.gId ORDER BY date DESC';
$result=mysql_query($query) or die ('Error in Query: $query.' . mysql_error());
// echo 'successful query';
if (mysql_num_rows($result) > 0)
{
// echo 'rows found';
while($row=mysql_fetch_assoc($result))
{
// print_r($row);
echo '<div class="newsitem"><div class="h2" align=left>' . date("d F Y", $row['date']) . ' - ' . $row['title'] . '</div>';
if ($row[thumb] != 'NULL')
{
echo '<div class=imagethumb><img src="' . $row[thumb] . '"></div>';
echo '<div class="imagetext"><div class="body">' . nl2br($row['info']) . '</P></div></div></div>';
}
else
{
echo '<P class="body">' . nl2br($row['info']) . '</P></div>';
}
}
}
else
{
echo 'No Rows Found';
}
mysql_free_result($result);
mysql_close($connection);
?>
</div>
</div>
</div>
</div>
<BR>
<div align="center">
Website Created and Maintained By Edward Caine
</div>
</script>
</body>
</html>
Now when the join comes across an item that doesn't have a corresponding image it should come out 'NULL' and it should move on to the code just displaying the text, but instead it presents an empty imagebox divider and the text in an imagetext divider for everything. (i.e. it executes everything as if the 'if' statement were correct). If I change it to if ($row[thumb] == 'NULL') then it formats everything in the manner of the 'else' clause.
I've attached a screen picture of the result of both if ($row[thumb] == 'NULL') and if ($row[thumb] != 'NULL').
Anybody got any ideas?
Thanks
Edd