Results 1 to 5 of 5

Thread: iteration in a loop

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default iteration in a loop

    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 Code:
    <?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++;
    }

    ?>
    Last edited by ggalan; 11-09-2010 at 03:39 AM.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    PHP Code:
    <?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.
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    i trimmed down the code, the url should be something like
    PHP Code:
    product.php?id=someNumber&col=
    there is also an array
    PHP Code:
    $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?

  4. #4
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    not sure if this helps

  5. #5
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    PHP Code:
    <?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++;
    }

    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •