How to make this code to loop 10 times per page?
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbs开发者_开发百科ql", $con);
$result = mysql_query("SELECT * FROM testimonial where approved='Yes'");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Review</th>
<th>Date</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['full_name'] . "</td>";
echo "<td>" . $row['review'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
If you are looking for that specific block of data to loop 10 times every time the page is loaded simply use a for() loop
for($i=0;$i<10;$i++)
{
// block of data
}
But I assume that that is not what you are asking since it would be impractical (as far as I can see).
To print 10 results, add
limit 10
to the end of your query. If you're using pagination, however, you will need to start the limit somewhere (e.g. limit STARTING_NUMBER, NUM_OF_RESULTS)
Good luck!
Dennis M.
replace
SELECT * FROM testimonial where approved='Yes'
with
$offset = 0; //calculate your offset here as per page;
SELECT * FROM testimonial where approved='Yes' limit $offset, 10
精彩评论