Archive

Posts Tagged ‘Rb’

html/php/mysql display images side by side?

July 7th, 2012 2 comments

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])