Give this a whirl, let us know what you get.
PHP Code:
<?php
#displayNewsList.php
$sSQL = 'SELECT id, title FROM news';
$rResult = mysql_query($sSQL);
while ($aNewsItem = mysql_fetch_assoc($rResult))
{
printf('<a href="displayNewsItem.php?newsid=%s" title="%s">%s</a><br />',
$aNewsItem['id'],
$aNewsItem['title'],
$aNewsItem['title']
);
}
#displayNewsItem.php
if(isset($_GET['newsid']) && !empty($_GET['newsid']) && ctype_digit($_GET['newsid']))
{
$sSQL = sprintf("SELECT title, content FROM news WHERE id = %s",
$_GET['newsid']
);
$rResult = mysql_query($sSQL);
if(!is_resource($rResult))
{
echo '<h3>System Error</h3>';
echo '<p>' . mysql_error() . '</p>';
exit;
}
if(mysql_num_rows($rResult) === 1)
{
$aNewsItem = mysql_fetch_assoc($rResult);
printf('<h3>%s</h3><p>%s</p>',
htmlentities($aNewsItem['title']),
htmlentities($aNewsItem['content'])
);
}
else
{
echo '<h3>Invalid News Item</h3>';
echo '<p>Sorry, no article could be found matching your request.</p>';
}
}
else
{
echo '<h3>Invalid News Item</h3>';
echo '<p>Sorry, you failed to specify a valid article.</p>';
}
?>
Bookmarks