Search code examples
phpmysqlhtml-tabledreamweaver

How to echo two rows with four column


How to echo two rows with four column

this is showing like this http://www.koolfree.com/ImageUpload/uploads/1385306598.jpg

and I want like this http://www.koolfree.com/ImageUpload/uploads/1385348807.jpg

How can I do this? Please help me to fix this issue.

<?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(); 
    ?>

Solution

  • change your while loop like follows

    <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>