I'm using the same while loop on two pages where the only difference is a different SQL call on each page. The first works as it should, grabbing the contents from the query and displaying it in an image slider:
<?php
$qry = mysql_query(sprintf("SELECT * FROM manageme WHERE element IN ('%s')", $element));
$i = 0;
while (($t = mysql_fetch_array($qry)) != null && $i < 52) { $i++;?>
<li>
<a href="">
<img src="<?php print $t['fileLocation']; ?>";
title="<?php print $t['element_name']; ?>";
name="<?php print $t['clickLocation']; ?>";
alt="wat"
class="btnshow" />
</a>
</li>
<?php } ?>
This works as it should stepping through the loop and grabbing the contents from the query so long as there are less than 52 entries returned, ending when each record has displayed once.
Upon implementing the same while loop with a different SQL call, the problem occurs.
<?php
$qry = mysql_query(sprintf("SELECT u.username, us.user_id, us.service_id,
s.imageID, s.title, s.clickLocation, s.fileLocation, s.element_name
FROM user u, user_service us, manageme s
WHERE us.user_id = %s
AND s.imageID = us.service_id", $_COOKIE['user_id']));
$i = 0;
while (($t = mysql_fetch_array($qry)) != null && $i < 52) { $i++;?>
<li>
<a href="">
<img src="<?php print $t['fileLocation']; ?>";
title="<?php print $t['element_name']; ?>";
name="<?php print $t['clickLocation']; ?>";
alt="wat"
class="btnshow" />
</a>
</li>
<?php } ?>
Instead of grabbing from the array and ending the while loop when the contents have displayed once, it continues to loop the contents in the image slider until 52 entries have been displayed. So for instance, if the SQL call only finds 4 records to display in the image slider, the set of 4 displays 13 times (52/4) before ending the loop.
Can anyone help me figure out how to end this loop after it has displayed each record from my database once and only once? Thanks in advance!