View Full Version : Resolved iteration in a loop
ggalan
11-09-2010, 02:34 AM
i have a loop that outputs ul li items. in it i have an image with an anchor tag. inside the href for each of those, i want to be able to reference "this" particular number
<?php
$nCount = 0;
while ($nCount<=$num){
echo "<li>";
echo "<a href='product.php?";
>>>>>>>echo this $nCount <<<<<<<<????
echo "'><img src='assets/main_small/";
echo $aL[$nCount];
echo"_";
echo $row0['productID'];
echo".jpg";
echo "' width='' height='' /></a>";
echo "</li>\n";
$nCount++;
}
?>
bluewalrus
11-09-2010, 02:58 AM
<?php
$nCount = 0;
while ($nCount<=$num){
?>
<li><a href='product.php?<?php echo $nCount; ?>'><img src='assets/main_small/<?php echo "$aL[$nCount]_$row0['productID']";?>.jpg' width='' height='' /></a></li>
<?php
$nCount++;
}
?>
product.php?number
Doesnt make any sense to me. You haven't set a variable to contain the value or value to be passed to it if it is a variables name.
ggalan
11-09-2010, 03:06 AM
i trimmed down the code, the url should be something like
product.php?id=someNumber&col=A
there is also an array
$aL = array("A", "B", "C", "D", "E", "F");
so when user clicks a button from the loop
the iteration from it will choose its respective number "$nCount"
and that will also determine the index of the array
so the question is, how do i pass the value of the respective button clicked?
ggalan
11-09-2010, 03:17 AM
not sure if this helps
ggalan
11-09-2010, 03:38 AM
<?php
$nCount = 0;
while ($nCount<=$num){
echo "<li>";
echo "<a href='product.php?";
$link = "id=".$id."&view=".$aL[$nCount];
echo $link;
echo "'><img src='assets/main_small/";
echo $aL[$nCount];
echo"_";
echo $row0['productID'];
echo".jpg";
echo "' width='' height='' /></a>";
echo "</li>\n";
$nCount++;
}
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.