How do you get php to show 5 rows from mysql
Then create a new line and show another 5 ect....
Thank you
How do you get php to show 5 rows from mysql
Then create a new line and show another 5 ect....
Thank you
Use the LIMIT clause if you want to limit the amount of results returned from the query.
If you want to print an <hr/>
after every fifth record you can check it via the modulus operator:
$counter = 1;
while ($row = mysql_fetch_assoc($rst)) {
// print $row stuff
if ($counter % 5 == 0)
print "<hr />";
$counter++;
}
Basically, we have a variable used to count how many records we've printed. Once that counter can be divided by five, and leave no remainder, we print our horizontal-rule.
Err.. you mean something like:
SELECT * FROM `tablename` WHERE ... LIMIT 5
Something like this is maybe helpfull:
$result = mysql_query($query);
if($result){
while($row = mysql_fetch_assoc($result)){
if(++$i%5==0 && $i>0){
/* do the extra thing... new line some styles */
}
}
}
$total = 20;//get total number here;
$limit = 5;
for($i = 0;$i< $total/$limit;$i++)
{
$sql = $result = $rows = "";
$start = $limit * $i;
$sql = "select * from m_table order by id desc limit $start,$limit";
$result = mysql_query($query);
while($rows = mysql_fetch_assoc($result))
{
//print the result here;
}
}
so,you can fetch 5 rows every time from mysql,but not fetch all the rows one time.