Forum Moderators: coopster

Message Too Old, No Replies

getting duplicate images in display page

No duplicates in results

         

manic

5:44 pm on Jul 11, 2007 (gmt 0)

10+ Year Member



Please HELP!

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>
&nbsp;&nbsp;
<?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>

supermanjnk

8:22 pm on Jul 11, 2007 (gmt 0)

10+ Year Member



The reason each row shows three of the same image is that you are calling the same variable in the same instance of the loop for each of them.

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

manic

9:57 pm on Jul 11, 2007 (gmt 0)

10+ Year Member



Thanks for the reply!

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.

supermanjnk

10:24 pm on Jul 11, 2007 (gmt 0)

10+ Year Member



You need to integrate this code into yours, Obviously I don't have the data you are outputting so I just created a loop that would loop through x ammount of times.

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.

manic

2:15 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



I finally got it to work. I've been working on it for over a week (I hate to admit that I can't).

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. :)