Limiting links in php

Discussion in 'PHP' started by JCOnline, Feb 22, 2013.

  1. #1
    I find it difficult to limit the number of links displayed:

    <?php
                            $websites = $data->select ( "Website_Tag" , "*", array ( "TagID" => intval ( $tag_web["TagID"] ) ) );
                            if ( ! empty ( $websites ) )
                                foreach ( $websites as $website ) :
                                    $web_detail = $data->select ( "Website" , "*" , array ( "WebsiteID" => $website["WebsiteID"] ) );
                                    $web_detail = $web_detail[0];
                        ?>
     
    <a href="<?php echo base_url.get_sef_url ( $website["WebsiteID"] , "Website" ) ?>/"><?php echo $web_detail["WebsiteName"] ?></a>
     
                        <?php
                        endforeach;
                        ?>
    PHP:
    What can I do to limit the generated links?
     
    Solved! View solution.
    JCOnline, Feb 22, 2013 IP
  2. #2
    Just add before the foreach the following line
    $counter = 0;
    PHP:
    Add just next to the foreach the following line
    
    $counter++; 
    if ($counter > 5) break;
    
    PHP:
    you can change the 5 to the number you need.
     
    EricBruggema, Feb 22, 2013 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,898
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #3
    You might also find the $data->select will take an option called "limit" that can be set to 5 (etc)
     
    sarahk, Feb 23, 2013 IP
  4. JCOnline

    JCOnline Greenhorn

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Thank you my friends. Problem solved.
     
    JCOnline, Feb 23, 2013 IP