I'm trying to get news items from my database, if the field in the table 'external' is 1 I want it to link to news_detail.php?ID=, but if 'external' is 0 I want it to get text from a table field, 'url' that has the link in it.
I think my problem is in the IF clause where I'm just using $external == 1, do I need to do something differently?
<?
// includes
include("../conf.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT * FROM news ORDER BY ID DESC";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
// if internal news item
if ($external == 1)
{
// iterate through resultset
// print article titles
while($row = mysql_fetch_object($result))
{
?>
<span class=textbody><li><a href="name_detail.php?ID=<? echo$row->ID; ?>"><? echo $row->headline; ?></a></li></span>
<?
}
}
// if external news item
// display external link
else
{
?>
<span class=textbody><li><a href="<? echo$row->url; ?>"><? echo $row->headline; ?></a></li></span>
<?
}
// close database connection
mysql_close($connection);
?>