SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    error is strange in for loop?

    Im getting this error
    http://mylaasp.com/provider_page.php?ID=39
    on
    PHP Code:
    for ($x 1$x 7$x++) {
        if(!empty($[
    'Img' $x])) {
        echo 
    "<a href=".${'Image'$x}" rel='lightbox[$Name]'>";
        echo 
    "<img src='".${'Image'$x}"' alt='".$Name."' class='thumb'>";
        echo 
    "</a>";
        }

    is everything ok with it if statement, as thats where the error is?
    (I think it looks ok)
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Regina, SK
    Posts
    318
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $['Img' $x
    is not valid code

    You probably want to read up on variable variables:
    http://ca.php.net/language.variables.variable

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    k

    k, im reading up on it, but I'm sort of slow so it might take a while, is the answer obvous?
    Thanks for the link though
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You might want to look up arrays.

    http://no.php.net/manual/en/function.array.php

  5. #5
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,644
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    I got confused with the variable variable thing and went with arrays, 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";
        }        

    "Oh, and Jenkins--apparently your mother died this morning."

  6. #6
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Your code contains many syntax errors.

    In general when working with arrays it would be better using something like this:

    PHP Code:
    $Photos = array('1' => array('path' => $Img1'name' => $Img1_name), '2' => array('path' => $Img2'name' => $Img2_name)); //etc

    foreach ($Photoes as key => $value
        {
      echo 
    "<a href=\"{$value['path']}\">";
      echo 
    "<img src=\"{$value['path']}\" alt=\"{$value['name']}\" class=\"thumb\">";
      echo 
    "</a>";
      echo 
    "\n";
      } 
    However, it is very difficult to come with any specific advice when we do not know anything more about what you are trying to do, as well as where the specific variables you use come from.


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
  •