我想设置输出限制,但我不知道如何以及在哪里。任何人都可以帮助我吗?
代码(摘录):
<?php
$row = mysql_fetch_array($result);
if ($row['Price'] == '0.00') {
echo "<TABLE width='100%'>\n";
echo "<TR><TD id=tblrowsHead2>Item</TD><TD id=tblrowsHead2>Size</TD><TD
id=tblrowsHead2>Contact</TD></TR>\n";
for ($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#E6E6FA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD id=Size>" . $row['Item'] . "</TD><TD id=Size>" . $row['Size']
. "</TD>
<TD id=Price>Contact Us</TD>\n";
}
} else {
echo "<TABLE width='100%'>\n";
echo "<TR><TD id=tblrowsHead2>Item</TD><TD id=tblrowsHead2>Size</TD><TD
id=tblrowsHead2>Price</TD></TR>\n";
for ($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if ($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#E6E6FA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"white\">\n";
}
echo "<TD id=Size>" . $row['Item'] . "</TD><TD id=Size>" . $row['Size']
. "</TD>
<TD id=Price>$" . $row['Price'] . "</TD>\n";
}
}
//now let's close the table and be done with it
echo "</TABLE>\n";
?>
答案 0 :(得分:0)
根据$ max值http://php.net/manual/en/function.array-chunk.php
在新闻项变量“actions”上使用数组块检查此输出 - &gt; print_r(array_chunk($ actions,$ max));
答案 1 :(得分:0)
这对我来说是最简单的方法:
//Generating the news items
$i=0;
if (is_array($actions)){
foreach($actions as $item)
if ($i < $max) {
// Build url like : pages/kalendar.php?year=1900&month=01&day=03&id=2&detail=1
$ds = $item['date_start'];
$link = $page_link.'?year='.(substr($ds,0,4)).'&month='.(substr($ds,5,2)).'&day='.(substr($ds,8,2)).'&id='.$item['id'].'&detail=1';
$i +=1;
?>