Code:
<?php
// Database connect //
include("../include/database.php");
// do stuff //
$usrname = $_GET['usrname'];
if (isset($_GET['id']) and is_numeric($_GET['id'])) {
$id = $_GET['id'];
} else {
exit ('invalid id');
}
$sql = mysql_query("SELECT * FROM site_comments WHERE artical_id = $id ORDER BY id DESC");
if (!$sql) {
exit ('Error retrieving comments..');
}
//Start Loop //
while ($row = mysql_fetch_array ($sql)) {
$numofrows = mysql_num_rows($sql);
print '<table width="100%" border="0" cellpadding="4" cellspacing="0" >';
//start colour changing loop//
for($i = 0; $i < $numofrows; $i++) {
$row = @mysql_fetch_array($sql);
// the ifelse //
if($i % 2)
{
print '<TR class="pink">';
}
else
{
print '<TR class="wight">';
}
//the output//
printf("<td>%s</td><td>%s</td>", $row["3"], $row["2"]);
//end colour changing loop//
}
}
print "</table>";
//end //?>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="addcomment"><a href="javascript:ajaxpage('includes-functions/site_comment_add.php?id=<? print $id ?>&usrname=<? print $usrname ?>', 'comadd');">Add a comment</a></td>
</tr>
<tr>
</table>
<div id="comadd">
</div>
Sorry to ask for help again guys, ok the above code works perfict except it always misses the newst entry to the database, if there are 5 it only prints the last 4. i been trying all day to work it out.
(and yes i dont know much about php and sql im learning a lot as i go though.)