small problem who helps

Discussion in 'PHP' started by vakantiewereld, Nov 11, 2010.

  1. #1
    this is my script but somthing is going wrong. It does not close who can help?
    <?php
    $aantalrijen=3;
    $teller=0;
    echo '<table><tr>';
    foreach ( $dataitems as $item ) {
    $u=$item['url'];
    $i=$item['img'];
    $f=$item['feed'];
    print '<td> <a title="'.$f.'" rel="nofollow" target="_blank" href="'.$u.'"><img src="'.$i.'" alt=""/></a></td>';
    }
    $teller++;
    if (! $teller % $aantalrijen)
    {
    echo "</tr>/n<tr>";
    }
    }
    ?>

    </tr></table></div></div>
     
    vakantiewereld, Nov 11, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    you have extra "}" before ?>
     
    bartolay13, Nov 11, 2010 IP
  3. vakantiewereld

    vakantiewereld Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no, than i get aphp error now it is my template that totaly smosched.
     
    vakantiewereld, Nov 12, 2010 IP
  4. irving

    irving Peon

    Messages:
    65
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your problem is that you have closed your foreach loop too soon:

    error:
    <?php
    $aantalrijen=3;
    $teller=0;
    echo '<table><tr>';
    foreach ( $dataitems as $item ) {
    $u=$item['url'];
    $i=$item['img'];
    $f=$item['feed'];
    print '<td> <a title="'.$f.'" rel="nofollow" target="_blank" href="'.$u.'"><img src="'.$i.'" alt=""/></a></td>';
    } // THE PROBLEM IS HERE
    $teller++;
           if (! $teller % $aantalrijen)
           { 
              echo "</tr>/n<tr>";
           }
    }
    ?>
    
    </tr></table></div></div>
    PHP:
    Correct:

    <?php
    $aantalrijen=3;
    $teller=0;
    echo '<table><tr>';
    foreach ( $dataitems as $item ) {
    $u=$item['url'];
    $i=$item['img'];
    $f=$item['feed'];
    print '<td> <a title="'.$f.'" rel="nofollow" target="_blank" href="'.$u.'"><img src="'.$i.'" alt=""/></a></td>';
    $teller++;
           if (! $teller % $aantalrijen)
           { 
              echo "</tr>/n<tr>";
           }
    } // Here is where the foreach loop should close
    ?>
    
    </tr></table></div></div>
    PHP:
     
    irving, Nov 12, 2010 IP
  5. vakantiewereld

    vakantiewereld Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Nope, now i get Parse error: syntax error, unexpected $end
    somthing is going wrong. Whiout the coloms and just getting the info everthing goes well but i want it in colloms.
    Greetings
    already thank 10 $ for the person who solves it
     
    vakantiewereld, Nov 12, 2010 IP
  6. irving

    irving Peon

    Messages:
    65
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I would need to see all the code for this page to help you further.
     
    irving, Nov 12, 2010 IP
  7. vakantiewereld

    vakantiewereld Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This is the original code
    so i want it in coloms and rows

    <?php // no direct access
    defined( '_JEXEC' ) or die( 'Restricted access' );

    function DatamerchantMenu(&$dataitems,&$params) {

    ?>
    <div class="module">
    <div class="mod_datamenu" style="text-align:center">
    <?php
    foreach ( $dataitems as $item ) {
    $u=$item['url'];
    $i=$item['img'];
    $f=$item['feed'];
    print '<a title="'.$f.'" rel="nofollow" target="_blank" href="'.$u.'"><img src="'.$i.'" alt=""/></a><br/><br/>';
    }
    echo "</div> </div>";

    }
     
    vakantiewereld, Nov 12, 2010 IP
  8. irving

    irving Peon

    Messages:
    65
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    <?php // no direct access
    defined( '_JEXEC' ) or die( 'Restricted access' ); 
    
    function DatamerchantMenu(&$dataitems,&$params) {
    ?>
    <div class="module">
    	<div class="mod_datamenu" style="text-align:center">
            <table>
                <tr>
    				<?php
    				$cols = 3;
    				$count = 0;
                    foreach ( $dataitems as $item ) {
                        $u=$item['url'];
                        $i=$item['img'];
                        $f=$item['feed'];
                        print '<td><a title="'.$f.'" rel="nofollow" target="_blank" href="'.$u.'"><img src="'.$i.'" alt=""/></a></td>';
    					$count++;
    					if($count == $cols){
    						print '</tr><tr>';
    						$count = 0;
    					}
                    }
                    ?>
                </tr>
    		</table>
    	</div> 
    </div>
    <?php
    }
    ?>
    PHP:
    checked this on my server (with the access restriction commented out) and there are no parsing errors (I would imagine the reason you got a parse error before was because I removed the final brace as I didn't know this was part of a function).
     
    irving, Nov 12, 2010 IP