Home > Action Sports Images > html/php/mysql display images side by side?

html/php/mysql display images side by side?

Hey Everyone,

Well what i am trying to do is display my categorys(with there picture) side by side. heres an example of what i am trying to do

action arcade
action.jpg arcade.jpg

shooting sports
shooting.jpb sports.jpg

right now it displays as the following

action
action.jpg

arcade
arcade.jpg

shooting
shooting.jpg

sports
sports.jpg

i am not sure if its something in my html i need to change or something i need to add from php or mysql. Here is what i currently have. name2 is the name of the category, products_image is the name of the image.

$result = mysql_query("SELECT products_image,name2 FROM categorypics order by pd_id");

while($row = mysql_fetch_assoc($result)) {
echo "<table>";
echo "<tr><td class=’categoryheads’>
$row[name2]</td></tr>";
echo "<td><img src=\"$row[products_image]\"
alt=\"\" /></td>\n";
echo "</table>";
}

if someone could explain what i am doing wrong, i would really appreciate it.

Thank you,
Rach

echo "<table><tr>";
while($row = mysql_fetch_assoc($result))
{
echo "<td class=’categoryheads’>
$row[name2]<rb/>";
echo "<img src=\"$row[products_image]\"
alt=\"\" /></td>\n";
}
echo "</tr></table>";
this will outputs
action…….arcade……..shooting…….sports
action.jpg..arcade.jpg..shooting.jpg..sports.jpg
if you want in on two lines:
$col = 0;
echo ("<table>");
while($row = mysql_fetch_assoc($result))
{
if ($col == 0)
echo ("<tr>");
echo "<td class=’categoryheads’>
$row[name2]<rb/>";
echo "<img src=\"$row[products_image]\"
alt=\"\" /></td>\n";
$col++;
if ($col == 2)
{
echo ("</tr>");
$cnt = 0;
}
}
echo "</tr></table>";

(replace <rb/> by the real thing [stupid editor])

  1. owsleyskid
    July 7th, 2012 at 07:31 | #1

    $row[name2]</td></tr>"; You’re closing the row and the table each time through the loop. The way you have the page structured, you probably need to do the query and the loop twice. Once for name2 and once for the image.

    echo "<table>";
    echo "<tr>";
    while($row = mysql_fetch_assoc($result)) {
    echo "<td class=’categoryheads’>
    $row[name2]</td>";
    }
    echo "</tr><tr>"
    PUT ANOTHER LOOP HERE FOR THE IMAGE ROW
    {
    echo "<td><img src=\"$row[products_image]\"
    alt=\"\" /></td>\n";
    }
    echo "</tr></table>
    References :

  2. just "JR"
    July 7th, 2012 at 07:37 | #2

    echo "<table><tr>";
    while($row = mysql_fetch_assoc($result))
    {
    echo "<td class=’categoryheads’>
    $row[name2]<rb/>";
    echo "<img src=\"$row[products_image]\"
    alt=\"\" /></td>\n";
    }
    echo "</tr></table>";
    this will outputs
    action…….arcade……..shooting…….sports
    action.jpg..arcade.jpg..shooting.jpg..sports.jpg
    if you want in on two lines:
    $col = 0;
    echo ("<table>");
    while($row = mysql_fetch_assoc($result))
    {
    if ($col == 0)
    echo ("<tr>");
    echo "<td class=’categoryheads’>
    $row[name2]<rb/>";
    echo "<img src=\"$row[products_image]\"
    alt=\"\" /></td>\n";
    $col++;
    if ($col == 2)
    {
    echo ("</tr>");
    $cnt = 0;
    }
    }
    echo "</tr></table>";

    (replace <rb/> by the real thing [stupid editor])
    References :

  1. No trackbacks yet.