Forum Moderators: coopster
I'm self-taught in HTML, JavaScript, and PHP/MySQL.
I've been working at this for quite a while learning as I go. I'm trying to get my images to display in a table (3 columns). I've looked at all of the items on the forums that I could find, and nothing comes closer than this.
I pull the correct number of results from the database, and the code is error free. The issue is that even though I can get 3 columns, the picture is identical for each row of 3. The embedded links work as they should. I just need some direction on displaying a single copy of each picture.
Below is the page "cleaned up" and working. I copied from just after the 'include' files.
$max_results = 30;
$result1=($page*$max_results) or die ('result1 error');
$from =($result1 - $max_results);
$array= "51";
$result= mysql_query("select distinct prod.company,prod.id,pix.image from products prod, pix where prod.id=pix.id and prod.category='$array' LIMIT ".$from.",".$result1) or die ('result error');
$rows1 = mysql_num_rows($result);
//print '$rows1 = '.$rows1;
$rows = mysql_fetch_array($result)or die (' array error');
while($row = mysql_fetch_array($result)){
$Company=$row['company'];
$ID=$row['id'];
$image=$row['image'];
?>
<center><table border="0" cellpadding="10">
<!--<img src="<?php echo $row['ImageLoc'];?>">-->
<tr><td><a href='<?php echo $row['company'],"_".$row['id'],".html";?>'><img src="<?php echo $row['image'];?>"width="150"></td>
<?php
$row++;
?>
<td><a href='<?php echo $rows['company'],"_".$row['id'],".html";?>'><img src="<?php echo $row['image'];?>"width="150"></td>
<?php
$row++;
?>
<td><a href='<?php echo $row['company'],"_".$row['id'],".html";?>'><img src="<?php echo $row['image'];?>"width="150"></td>
<?php
$row++;
}
?>
</table><br />
<?php
include 'pagebottom.html';
?>
<BR>
</BODY>
</HTML>
you have the following three times each time it loops:
<tr><td><a href='<?php echo $row['company'],"_".$row['id'],".html";?>'><img src="<?php echo $row['image'];?>"width="150"></td>
Each time it loops it's showing three table cells with the same $row['image']
You could modify this into your while loop and see if it works for you
<table border="1" width="100%">
<tr>
<?
$count = 33; // this should be mysql_num_rows($results);
$i = 1; // set $i to 1 to start the loop off at one.
while ($i<=$count) { // This should be your while loop
?><td>$row['image'] goes here</td><? // Put the image inside of this cell
if ($i%3) { // this checks divides the number by 3 and if there is no remainder it goes to the next row
} else {
if ($i >= $count) { // this checks to see if you've reached the count, to prevent extra Table rows
} else {
echo "</tr><tr>";
}
}
$i++;
}
?>
</tr>
</table>
If you'd like to learn more about this you can google php modulus or php arithmetic
This leaves me with 14 instances of the same picture. If I leave my original while statement in, and increment the output of it, I get 14 instances of each picture.
Any idea how I would rotate through the images without the original where statement?
Sorry, I've really missed this one somehow.
Try running the code I gave you by itself in a seperate file and you can see what it's doing.
You need to remove the while loop I used in there and put the rest of the code inside your loop.
I really must have been overwhelmed by this. Even with a good set of instructions, it took a while to sink in.
THANK YOU! Can't tell you how exciting it was to actually see the page display correctly. :)