Error: Warning: join() [function.join]: Bad arguments. in /home/glamour/public_html/functions/print3imagelinks.php on line 45

function Print3Links() {
$i = 1;
if ($i == "3"){ 
$link = rand(1,10);


switch ($link) {
case 1:
$output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1007' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1007(b).jpg'></a>";
  break;
case 2:
$output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1018' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1018(a).jpg'></a>";
    break;
case 3:
$output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>";
    break;
case 4:
$output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>";
    break;    
case 5: $output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; break;
case 6: $output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; break;
case 7: $output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; break;
case 8: $output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; break;
case 9: $output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; break;
case 10: $output[] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; break; } $output[] = ""; $i++; } return join('',$output); }

    Control paths exist in which $output does not exist and yet is used in the join() call. In particular, $i = 1, thus $i == "3" is false, hence the function is reduced to:

    function Print3Links() {
        $i = 1;
        if ($i == "3") {
            // not reached
        }
        return join('', $output);
    }
      if ($i <= "3"){ 
      $link = rand(1,10);
      

      So this works but only prints one... why??
      Also it's the last one why?

        NZ_Kiwis;10879498 wrote:
        if ($i <= "3"){ 
        $link = rand(1,10);
        

        So this works but only prints one... why??
        Also it's the last one why?

        If you are looking to output three image links.. I came up with:

        function Print3Links(){ 
           $i = 0; 
           while($i < 3){
              $link = rand(1,10); 
        
          switch ($link){ 
          case 1: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1007' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1007(b).jpg'></a>"; 
          break; 
          case 2: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1018' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1018(a).jpg'></a>"; 
          break; 
          case 3: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break; 
          case 4: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          case 5: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          case 6: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          case 7: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          case 8: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          case 9: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          case 10: 
          $output[$i] = "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"; 
          break;     
          } 
           echo $output[$i];
           ++$i;
           }
        }
        Print3Links();
        

        Cheers,

        NRG

        P.S Nice looking women 😉

        Edit: I think I misread your post... sorry bout that.. disregard..

          Great, thanks! I can see how I was going wrong!

          Also is there a way I can exclude the previous number from my random number?

            It would be better to do something like this:

            function PrintLinks($num) {
                if ($num <= 0) {
                    return;
                }
            
            $links = array(
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1007' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1007(b).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1018' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1018(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>",
                "<a href='http://www.glamourlingerie.co.nz/index.php?P=GL1013' border='0'><img src='http://www.glamourlingerie.co.nz/images/GL1013(a).jpg'></a>"
            );
            
            if ($num >= count($links)) {
                foreach ($links as $link) {
                    echo $link;
                }
            } else {
                $keys = array_rand($links, $num);
                foreach ($keys as $key)
                {
                    echo $links[$key];
                }
            }
            }

            After all, it does not make sense to limit the function to printing exactly 3 links. You might also consider returning the result array instead of printing it so that the caller can choose when to print it.

            Also is there a way I can exclude the previous number from my random number?

            My use of [man]array_rand/man does just that.

              Great code laserlight, any chance you can add comments to explain it if you get time

                any chance you can add comments to explain it if you get time

                Which part do you not understand? The idea is pretty simple: create an array and select at random $num elements of the array. Some code is there for validation (to check that $num is within range).

                Incidentally, this code:

                if ($num >= count($links)) {
                    foreach ($links as $link) {
                        echo $link;
                    }
                } else {
                    $keys = array_rand($links, $num);
                    foreach ($keys as $key)
                    {
                        echo $links[$key];
                    }
                }

                could be (arguably) simplified to:

                $count = count($links);
                $keys = ($num >= $count) ? range(0, $count - 1) : array_rand($links, $num);
                foreach ($keys as $key) {
                    echo $links[$key];
                }
                  Write a Reply...