display 2 or 3 images per row using php mysql

后端 未结 2 1189
情歌与酒
情歌与酒 2020-12-22 09:29

hi i\'m disaplyed images from mysql db table but it displays on by one means one row has one image. but i need 3 or 4 image per row. my coding is below. please give some ide

相关标签:
2条回答
  • 2020-12-22 10:10

    Do it in table like this, You might need to fix it a little bit, but it way how it will work

    <table>
    
    <?php 
            include_once("config.php");
            $result=mysql_query("SELECT * FROM merchant");
            $count = 0;
            while($res=mysql_fetch_array($result))
            {
                if($count==3) //three images per row
                {
                   print "</tr>";
                   $count = 0;
                }
                if($count==0)
                   print "<tr>";
                print "<td>";
                ?>
                        <?php echo $res['description'];?></p>
    
    
    
                        <img src="<?php echo $res['image'];?>" width="80" height="80"/>
    
    
    
                    <?php
                $count++;
                print "</td>";
            }
            if($count>0)
               print "</tr>";
            ?>
    
    </table>
    
    0 讨论(0)
  • 2020-12-22 10:13

    use a <table> to display.

    <?php 
        include_once("config.php");
        $result=mysql_query("SELECT * FROM merchant");
        $count = 0;
        echo '<table>';
        while($res = mysql_fetch_array($result))
        {
            if($count % 2 == 0) echo '<tr>';
            ?>
        <td>
            <p><?php echo $res['description'];?></p>
            <img src="<?php echo $res['image']; ?>" width="80" height="80"/>
        </td>
    <?php
        if($count % 2 == 0) echo '</tr>';
    } ?>
    
    0 讨论(0)
提交回复
热议问题