[英]How to echo two rows with four column
如何用四列回顯兩行
這就是這樣顯示的http://www.koolfree.com/ImageUpload/uploads/1385306598.jpg
我想要這樣http://www.koolfree.com/ImageUpload/uploads/1385348807.jpg
我怎樣才能做到這一點? 請幫助我解決此問題。
<?php
$max_results = 8;
$from = (($page * $max_results) - $max_results);
if(empty($_POST)) {
$query = "SELECT * FROM `noofbuilding` WHERE `buildingname` LIKE '".$letter."%' ORDER BY `buildingname` ASC LIMIT $from, $max_results";
}
$result = mysql_query("SET NAMES utf8"); //the main trick
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
echo '<div style="width:100%;" algin="center">';
echo "<table border='0' cellpadding='1' width='100%' bordercolor='000099'border='solid'>
";
echo "<tr>";
while($row = mysql_fetch_array($result))
{
echo "<td><div align='center'><img src='images/building_icon.gif' width='90' height='90'></a><p>" . $row['buildingname'] . "</p><div></td>";
}
echo "</tr>";
echo "</table>";
echo '</div>';
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as buildingname FROM noofbuilding ORDER BY buildingname ASC"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<p class=\"style2\">Pages: ";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['php_SELF']."?page=$prev&letter=$letter\" class=\"style2\">Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo " ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['php_SELF']."?page=$next&letter=$letter\" class=\"style2\">Next</a>";
}
echo "</p>";
mysql_close();
?>
首先獲得結果的數量作為加
$query = "SELECT *,count(*) FROM
noofbuilding WHERE
buildingname LIKE '".$letter."%' ORDER BY
buildingname ASC LIMIT $from, $max_results";
代替
$query = "SELECT * FROM
noofbuilding WHERE
buildingname LIKE '".$letter."%' ORDER BY
buildingname ASC LIMIT $from, $max_results";
加
$count =2;
$x = 0;
echo "<tr>";
while($ row = mysql_fetch_array($ result)&& $ x
echo "<td><div align='center'><img src='images/building_icon.gif' width='90' height='90'></a><p>" . $row['buildingname'] . "</p><div></td>";
}
回顯“”; 回顯“”; while($ row = mysql_fetch_array($ result)){
echo "<td><div align='center'><img src='images/building_icon.gif' width='90' height='90'></a><p>" . $row['buildingname'] . "</p><div></td>";
}
回顯“”;
`echo“的含義;
while($row = mysql_fetch_array($result))
{
echo "<td><div align='center'><img src='images/building_icon.gif' width='90' height='90'></a><p>" . $row['buildingname'] . "</p><div></td>";
}
echo "</tr>";`
如下更改您的while循環
<table width="100%" border="1" cellspacing="2" cellpadding="2">
<?php
$count=0;
while($row = mysql_fetch_array($result))
{
if($count%4==0)
{
echo "<tr/>";
echo "<tr>";
}
echo "<td><div align='center'><img src='images/building_icon.gif' width='90' height='90'></a><p>" . $row['buildingname'] . "</p><div></td>";
$count++;
}
?>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.