dcsimg
www.webdeveloper.com
Results 1 to 6 of 6

Thread: if statement inside a for loop?

  1. #1
    Join Date
    Aug 2004
    Posts
    195

    if statement inside a for loop?

    Im trying to duplicate this
    PHP Code:
    if(!empty($Img1)) {
    echo 
    "<a href='".$Image1."' rel='lightbox[$Name]'>";
    echo 
    "<img src='".$Image2."' alt='".$Name."' class='thumb'>";
    echo 
    "</a>";
    echo 
    "\n";
    }        
    if(!empty(
    $Img2)) {
    echo 
    "<a href=".$Image2." rel='lightbox[$Name]'>";
    echo 
    "<img src='".$Image2."' alt='".$Name."' class='thumb'>";
    echo 
    "</a>";
    }    
    if(!empty(
    $Img3)) {
    echo 
    "<a href=".$Image3." rel='lightbox[$Name]'>";
    echo 
    "<img src='".$Image3."' alt='".$Name."' class='thumb'>";
    echo 
    "</a>";
    }                
    if(!empty(
    $Img4)) {
    echo 
    "<a href=".$Image4." rel='lightbox[$Name]'>";
    echo 
    "<img src='".$Image4."' alt='".$Name."' class='thumb'>";
    echo 
    "</a>";
    }
    if(!empty(
    $Img5)) {
    echo 
    "<a href='".$Image5."' rel='lightbox[$Name]'>";
    echo 
    "<img src='".$Image5."' alt='".$Name."' class='thumb'>";
    echo 
    "</a>";
    }
    if(!empty(
    $Img6)) {
    echo 
    "<a href=".$Image6." rel='lightbox[$Name]'>";
    echo 
    "<img src=".$Image6." alt=".$Name."' class='thumb'>";
    echo 
    "</a>";
    }
    ?> 
    Heres what I have so far, but I get an error
    http://mylaasp.com/provider_page.php?ID=1
    PHP Code:
    for ($f 1$f 7$f++) {
        if(!empty(${
    'Img' $f})) {
        echo 
    "<a href='".$Image $f."' rel='lightbox[$Name]'>";
        echo 
    "<img src=".$Image $f." alt=".$Name."' class='thumb'>";
        echo 
    "</a>";
        echo 
    "\n";
        }        

    Thanks...
    Last edited by lukeurtnowski; 11-18-2006 at 05:01 PM.

  2. #2
    Join Date
    Aug 2004
    Posts
    195
    is this ok?
    PHP Code:
    $Photos = array(=> $Img1$Img2$Img3$Img4$Img5$Img6);

    for (
    $f 1$f 7$f++) {
        if(!empty(
    $Photos['f']})) {
        echo 
    "<a href='".$Image$f ."' rel='lightbox[$Name]'>";
        echo 
    "<img src=".$Image$f ." alt=".$Name."' class='thumb'>";
        echo 
    "</a>";
        echo 
    "\n";
        }        


  3. #3
    Join Date
    Jan 2006
    Location
    Israel
    Posts
    178
    PHP supports variable variable names, i know that sounds odd.

    To state that a name of a variable, is a variable, you must put two dollar signs before the
    name of the variable...

    I never bothered understanding how does this odd feature works...
    you can just simply use arrays with a varible as an index instead, in the following manner:

    PHP Code:
    $img[$i

  4. #4
    Join Date
    Aug 2004
    Posts
    195
    k, great, that worked.
    Now how come when I do this, only the variable f appears
    PHP Code:
        echo "<a href='".$Image$f ."' rel='lightbox[$Name]'>"

  5. #5
    Join Date
    Oct 2005
    Posts
    843
    try:
    PHP Code:
    echo '<a href="' $Image $f '" rel="lightbox[' $Name ']">'
    also, any chance you are using lighbox? ii think it was just your quotes getting mixed up and not having them in the right place cause the $name variable was inside them making it just appear as $name in the html code.

  6. #6
    Join Date
    Aug 2004
    Posts
    195
    ok, thanks. nice read.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles