SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot boognish's Avatar
    Join Date
    Sep 2005
    Location
    Leeds
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I limit an array to one row?

    This should be an easy one, but I don't know how to do it myself. Basically I have an array read from an csv file to display a featured property. The problem is, if the client selects more than one property as "featured" by mistake in their property uploading software it displays every property thats featured in the array, when ideally I only want it to display one featured property on the homepage, otherwise it messes up the page. So my question is how do I limit the array to display only the first row that has the "featured" variable?

    http://click-let.com/click/index.php

    PHP Code:
    <?php $handle fopen("cfp/xfile.txt""r"); 

    while ((
    $data fgetcsv($handle1000",")) !== FALSE): 

    $featured $data[31];
    if (
    $featured==FEATURED) {?>
    <p><?php echo $data[2?></p>
    <br />
    <p>&pound;<?php echo number_format($data[7], 2); ?> pcm, Rooms: <?php echo $data[8?></p>
      <p> <a href="javascript:pop('details.php?id=<?php echo $data[1?>');">(more)</a></p>

       <?php
        
    }
        endwhile; 
    ?>
    Last edited by boognish; Nov 20, 2008 at 16:12.

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try using continue to break out of the loop once a featured home is found.

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    http://www.php.net/manual/en/control...ures.break.php

    I tried to add the break in your code, but you messed it up cutting and pasting, so just try it yourself

  4. #4
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    982
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    break; will exit the while loop completely while continue; will move the loop to the next node.
    MySQL v5.1.58
    PHP v5.3.6

  5. #5
    SitePoint Zealot boognish's Avatar
    Join Date
    Sep 2005
    Location
    Leeds
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the help, break; worked perfectly. I figured it was a simple solution


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
  •