如何用四列回显两行

时间:2013-11-24 10:16:23

标签: php mysql html-table dreamweaver

如何用四列回显两行

这是这样的 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(); 
    ?>

2 个答案:

答案 0 :(得分:0)

首先获得结果数量 添加

$query = "SELECT *,count(*) FROM {noofbuilding {1}} {buildingname {1}} {buildingname {1}}

而不是

WHERE {noofbuilding {1}} {buildingname {1}} {buildingname {1}} 添加

LIKE '".$letter."%' ORDER BY

while($ row = mysql_fetch_array($ result)&amp;&amp; $ x

ASC LIMIT $from, $max_results";
回声&#34;&#34 ;;   echo&#34;&#34 ;; while($ row = mysql_fetch_array($ result))     {

$query = "SELECT * FROM
回声&#34;&#34;;

insteaad“echo&#34;&#34 ;;

WHERE

答案 1 :(得分:0)

更改你的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>