Search code examples
phpdatabasetabular

Table repeat region


I am pulling two different variables from the database. A name, and an image path. I want to display this on the page to look like this:

|Image 1|Image 2|Image 3|

|Name 1 |Name 2 |Name 3 |

I currently have this code:

<?php do { ?>
<img src="<?php echo $row_UserInfo['image_path'];?>" width="150" height="150"/>
<a href="HorseProfile.php?recordID=<?php echo $row_UserInfo['id']; ?>"style="color:#000000; text-decoration: none; text-align: center;">
<?php echo $row_UserInfo['Name']?></a>
<?php } while ($row_UserInfo = mysql_fetch_assoc($UserInfo)); ?>

I tried to add a break after the image so that the name goes right under it, but then when the next image appears, it goes next to the name before. I know this is probably extremely simple, but this has been a problem for me for a while and if someone could open my eyes and show me what I'm doing wrong, that would be deeply appreciated.


Solution

  • You should enclose your image and link in a div, and then float the div. Here is an example:

    <?php do { ?>
        <div style="float:left;">
            <div>
                <img src="<?php echo $row_UserInfo['image_path'];?>" width="150" height="150"/>
            </div>
            <div>
                <a href="HorseProfile.php?recordID=<?php echo $row_UserInfo['id']; ?>"style="color:#000000; text-decoration: none; text-align: center;">
                    <?php echo $row_UserInfo['Name']?>
                </a>
            </div>
        </div>
    <?php } while ($row_UserInfo = mysql_fetch_assoc($UserInfo)); ?>