SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast cfpmedia.com's Avatar
    Join Date
    Nov 2010
    Location
    California, USA
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Display Block of Code for Each Record in Database

    Hello,

    I am attempting to display a set of links based off of information from my database.
    However, my current attempts cause some issues.

    You see, I am using the while statement to display a simple <a href=""></a> followed by two new lines per each record in the table.
    However, this causes two new lines at the end of the page, even though I have no use for it for the last record.

    Is there any way to display things for each record, and a different one for the last record?
    I don't want extra spacing if nothing follows the last record.

    Thanks,
    Eric

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,069
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Put something after every record except the last = put something before each record except the first. Using that logic, you can use something like

    PHP Code:
    $first=true;
    foreach(
    $record as $rec) {
       if (!
    $first) echo '<br /><br />';
       
    // do something with $rec
       
    $first=false;

    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast cfpmedia.com's Avatar
    Join Date
    Nov 2010
    Location
    California, USA
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.


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
  •