I've been having some trouble with mysql. The problem is with the following code. I am trying to make a news script, but when it shows them on the screen, they are all the same entry. I have no idea why it won't work.
config.php - My database information
templates.php - template; sort of working 😕
index.php - main page
index.php
<?php
//Require config
require("data/config.php");
include("templates/templates.php");
include("templates/css.php");
//Connect to database
mysql_connect($hostname, $username, $password);
mysql_select_db($database);
//Count the rows, display only $n_entries
$query = mysql_query("SELECT * FROM news");
$num_rows = mysql_num_rows($query);
$disp = $num_rows - $n_entries;
if ($disp < 1) {
$disp = 1;
}
$q_news = mysql_query("SELECT * FROM news WHERE id >= $disp ORDER BY id DESC");
//Here it all comes together
echo $css;
while ($newse = mysql_fetch_array($q_news)) {
$ncq = mysql_query("SELECT * FROM comments WHERE nid = '$newse[id]'");
$nc = mysql_num_rows($ncq);
$title = $newse['title'];
$posted = $newse['poster'];
$news = $newse['news'];
$id = $newse['id'];
$template = str_replace("{title}", $title, $template);
$template = str_replace("{posted}", $posted, $template);
$template = str_replace("{news}", $news, $template);
echo $template;
}
?>
templates.php
<?php
$template = <<<TEMPLATE
<table width="600" class="table" cellpadding="1" cellspacing="3" border="0" align="center">
<tr valign="middle">
<td width="60" height="60" class="avatar">
</td>
<td width="540" height="60" class="info">
{title} <br>
{posted}
</td>
</tr>
<tr valign="top">
<td width="600" class="news" colspan="2">
{news}
<div align="right">
<a href="{$full_path}print.php?id={$id}">Printable Page</a>
</div>
</td>
</tr>
</table>
<br>
TEMPLATE;
?>
To see what the problem I am having is, go here:
http://ahrenp.com/eznews