Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Unhappy help with this for pls

    I have problems with this code:

    PHP Code:
    <?php 
            $tope
    =15;
            for (
    $i=1$i<=15$i++){
                
                if(
    $i==15){
                    
    $COMITA="";
                }else{
                    
    $COMITA=",\r\n";
                }
                
                
            if(
    $rq['img'.$i.'']!=""){
                echo 
    '["thumbmm.php?src=news/'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]'.$COMITA;
            }
            }
            
    ?>
    I need to set empty $COMITA on my last cycle but I don't know why.
    NOTE: My if condition is checking what field isn't empty on my db by this way the result can be variable.

    Regards

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    And this is why indiscript variables suck. I'm not really sure what you're code is doing... echoing out something for javascript? Flash?

    Whats wrong with it?

  • #3
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    may be there is no $rq['img15'] ?

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Christ, that code is overly complex.

    Code:
    $count = 1;
    
    while ($count <= 15)
    {
        if ($rq['img'.$count])
        {
            echo '["thumbmm.php?src=news/'.$rq['img'.$count].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]';
        }
        echo (($count++ != 15) ? "\r\n" : '');
    }
    Last edited by MattF; 11-09-2010 at 08:47 PM.

  • #5
    Regular Coder
    Join Date
    Sep 2010
    Location
    Virginia
    Posts
    112
    Thanks
    11
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by urgido View Post
    I have problems with this code:

    PHP Code:
    <?php 
            $tope
    =15;
            for (
    $i=1$i<=15$i++){
                
                if(
    $i==15){
                    
    $COMITA="";
                }else{
                    
    $COMITA=",\r\n";
                }
                
                
            if(
    $rq['img'.$i.'']!=""){
                echo 
    '["thumbmm.php?src=news/'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]'.$COMITA;
            }
            }
            
    ?>
    I need to set empty $COMITA on my last cycle but I don't know why.
    NOTE: My if condition is checking what field isn't empty on my db by this way the result can be variable.

    Regards

    PHP Code:
    <?php 
            
    for ($i=1$i<=15$i++){

            if(
    $rq['img'.$i.'']!=""){
                echo 
    '["thumbmm.php?src=news/'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]'.$COMITA;
            }
            }
    unset(
    $COMITA);
            
    ?>

  • #6
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    thanks all.

    I solved this f* problem my self.

    PHP Code:
    <?php 
            $tope
    =15;
            for (
    $i=1$i<=15$i++){
                
                if(
    $i==15){
                    
    $COMITA="\r\n";
                }else{
                    
    $COMITA=",\r\n";
                }
                
                
            if(
    $rq['img'.$i.'']!=""){
                
                
                
    $slideIM[]='["thumb.php?src=news'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]';
                
            }
            }
            
            
    $ultimaIMG=end($slideIM);
                
                foreach(
    $slideIM as $imagenes){
                    
                    if(
    $ultimaIMG==$imagenes){
                        echo 
    $imagenes."\r\n";
                    }else{
                        echo 
    $imagenes.",\r\n";
                    }
                    
                }
            
            
    ?>

    the goal my foreach LoL!

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,974
    Thanks
    15
    Thanked 229 Times in 229 Posts
    Are you making a javascript array? Push is very simple to use for that, and also for PHP arrays, and you don't have to worry about removing the last comma.

  • #8
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts
    DrDos you're right, but I use jquery library that need to be removed my last comma. I don't know why.


  •  

    Posting Permissions

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