I'm quite new to PHP and I'm looking to have a ID pulled from my Database to show a Image in a table and have it alternate in each column.

Right now I have the following.

    <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="white">
        <tr bgcolor="#CCCCCC" align="center">
            <td width="36%"><h4>Image</h4></td>
        </tr>
    <?php
        $query = "SELECT * FROM retail_achievements WHERE game_id = '$gameID' && achievement_locked = '0' ORDER BY achievement_id ASC";
        $result = mysql_query($query);
        while($row = mysql_fetch_assoc($result)) {   // Start looping table row
        $gameID = $row['game_id'];
        $achievementID = $row['achievement_id'];
    ?>
        <tr align="center" bgcolor="#eeeeee">
            <td> <img src="images/achievements/<?php echo $gameID; ?>/<?php echo $achievementID; ?>.jpg" /> </td>        </tr>

    <?php
    } // end of while loop
    ?>
</table>

This will display the images one by one but I would like side by side.

Thanks for any help!

Recommended Answers

All 3 Replies

Member Avatar for LastMitch

@DarkSynopsis

I assume this code works.

To do side by side, it's more CSS issue than a PHP issue. To make it side by side you need to do this <tr><td></td><td></td></tr>

From this:

<tr align="center" bgcolor="#eeeeee">
<td> 
<img src="images/achievements/<?php echo $gameID; ?>/<?php echo $achievementID; ?>.jpg" /> </td>        
</tr>

To this:

<tr align="center" bgcolor="#eeeeee">
<td> 
<img src="images/achievements/<?php echo $gameID; ?>/<?php echo $achievementID; ?>.jpg" /> 
</td>   
<td> 
<img src="images/achievements/<?php echo $gameID; ?>/<?php echo $achievementID; ?>.jpg" /> 
</td>
</tr>

Problem with that is it does not alternate the Image I end up getting

Image1 Image1
Image2 Image2

When I want

Image1 Image2
Image3 Image3

Member Avatar for LastMitch

@DarkSynopsis

Problem with that is it does not alternate the Image I end up getting

In order to get the image side by side. You need another column so you can separate the images.

Your Column:

$query = "SELECT * FROM retail_achievements WHERE game_id = '$gameID' && achievement_locked = '0' ORDER BY achievement_id ASC";

New Column:

"SELECT column_name1, column_name2 FROM table_name WHERE column_name=operator value"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.