I have some code which retrieves user comments from my database:
$comments = mysql_query("SELECT * FROM comments WHERE ref = '$theID'LIMIT 0, 3;")
or die(mysql_error());
while ($rowC = mysql_fetch_array($comments)) {
echo "<p>On " .$rowC['date']. ", ";
echo $rowC['username']. " said: <br/>";
echo $rowC['comment'];
echo "</p><hr/>";
}
if (mysql_num_rows($comments) == 0) {
echo "<p>(No comments have been made yet)</p>";
}
Comments are stored with a unique user reference in the database, and retrieved where they match the user id, this is called at the top of the page:
$theID = $_GET['id'];
What I am trying to do is limit the comments shown, and if there are more than 3, show a 'click to see more' type button or link which displays all the user comments on the same page in the same way as above.
UPDATE, i am now using this, Trying to implement Johan's suggestion, but still cant get it to display more when link is clicked:
$comments = mysql_query("SELECT * FROM comments WHERE ref = '$theID' LIMIT 0, 4") or die(mysql_error());
while ($rowC = mysql_fetch_array($comments)) {
echo "<p>On " .$rowC['date']. ", ";
$username = htmlspecialchars($rowC['username']). " said: <br/>";
echo $username;
$comment = htmlspecialchars($rowC['comment']);
echo $comment;
echo "</p><hr/>";
}
$num_rows = mysql_num_rows($result);
if ($num_rows > 3) {
$query = "SELECT * FROM comments WHERE ref = '$theID' LIMIT 4, 20";
} echo "<p><a href=''>click to see more</a></p>";
if (mysql_num_rows($comments) == 0) {
echo "<p>(No comments have been made yet)</p>";
}