Results 1 to 3 of 3

Thread: php echo data

  1. #1
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default php echo data

    Hi, I am wondering if anyone could help me here I have trying to sort this 1 out for a while now

    Here I have the php code which gets data from mysql, and echo’s it on the browser, problem is it echo’s all the fields of data, and I just like it to echo the first fields only.

    so, it echo’s the newest field record only first by title, or id, then date, then listing just once.


    <?php

    // query db
    $sql = mysql_query ("SELECT listingid, Title, Date, Listing, DATE_FORMAT(Date, '%d-%m-%Y') as Date FROM `track-listing` ORDER BY Date DESC");
    // echo result from db
    while ($row = mysql_fetch_assoc($sql)){
    echo "{$row['listingid']}" .
    ($row['Title']) . "<font size=1 color=#878787>" . "* :: *" . ($row['Date']) . ($row['Listing']) . "</font>" . "<br>";

    }
    ?>

    Any help and suggestion is greatly appreciated
    Last edited by john0611; 03-13-2009 at 09:46 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    add "LIMIT 1" to your query:

    PHP Code:
    $sql mysql_query ("SELECT listingid, Title, Date, Listing, DATE_FORMAT(Date, '%d-%m-%Y') as Date FROM `track-listing` ORDER BY Date DESC LIMIT 1"); 

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    john0611 (03-13-2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    FANTASTIC! Just what i needed!

    Thank you for your help!

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
  •