0

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

<?php 
    include_once("config.php");
    $result=mysql_query("SELECT * FROM merchant");
    while($res=mysql_fetch_array($result))
    {
?>
<?php echo $res['description'];?></p>
    <img src="<?php echo $res['image'];?>" width="80" height="80"/>
<?php } ?>
2
  • Please make your code readable so people will be interested in looking at it. Commented Sep 5, 2012 at 11:22
  • @Farid He asked 5 questions already. Fluffeh, you are right, thanks for the link! Commented Sep 5, 2012 at 11:29

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

Comments

0

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>';
} ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.