#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    23
    Rep Power
    0
    Hey everyone. Once again, I have a question...

    I need to retrieve the most recent additions to a table where column name='$string'

    My question is that of these records returned, I need to diplay THE MOST RECENT record in one place on the html page, and then display the others (in order from newest to oldest) in another place...

    I can pull the records with a select statment, and I understand the ORDER BY statement that follows, but how do I split the results as above?

    ** The records have a 'date/time' column, and a 'category' column that I will use to perform the select statement...**

    As Always, Thanks everyone for any help/advice you may be able to offer me.

    Regards,
    rainmaker
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    If you want get last record first then use following sql statement.


    "SELECT * FROM tablename WHERE column name='$string'order by datefield DESC"


    //DESC will display record in descending order.





    ------------------
    SR -
    webshiju.com

    "The fear of the LORD is the beginning of knowledge..."
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    23
    Rep Power
    0
    Right, and I understand that will list all records returned in desc order. I will need to add a LIMIT statement so that it only returns the last 6 or so entries- not a problem there, either. I know how to do this. My question follows:

    BUT- of the records returned, I need to list the first one returned in one area, and then, like the next 5 (results numbered 2-6) in another place. This is where my question lies...

    Say that I perform a query to mysql that returns 6 records... How do I display record results 2-6, ignoring the 1st record returned?
    I have the need to display the 1st record result in one area, and the other results in another.. but i can't seem to list the others while excluding the first record returned...

    Thanks for your time.
    regards,
    rainmaker
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    try mysql_data_seek()....

    $query="select * from table_name order by something limit n";
    $result=mysql_query($query, $link);
    $affected=mysql_num_rows($result);

    // skip first record and get the rest
    for($i=1; $i<$affected; $i++)
    {
    mysql_data_seek($result, $i);
    $row=mysql_fetch_row($result);
    print"$row[0] and $row[1]....$row[n]"; // or store them in an array or whatever
    }

  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    23
    Rep Power
    0
    KYUZO- THANKS!!! the following works like a dream...
    (I'm posting so others may use it.)
    <?php

    require ("require.phtml");

    $query = mysql_query("SELECT * FROM content_table WHERE (author_id='Yoda')ORDER BY date DESC LIMIT 6",$db);
    $affected = mysql_num_rows($query);
    for($i=1; $i<$affected; $i++)
    {
    mysql_data_seek($query, $i);
    $myrow=mysql_fetch_array($query);
    printf("<b>id: %s </b>title: <b>%s</b>detail: <b>%s</b><br><br>n", $myrow["id"], $myrow["title"], $myrow["detail"]);
    }

    ?>

    This only returns the 5 oldest records of the 6 selected, ignoring the 1st returned entry..... EXACTLY what I needed to do. THANKS AGAIN!

    rainmaker

Similar Threads

  1. select verification onsubmit
    By DrStein in forum HTML Programming
    Replies: 3
    Last Post: January 20th, 2004, 03:16 AM
  2. select distinct problem
    By mrengc in forum MS SQL Development
    Replies: 1
    Last Post: December 23rd, 2003, 07:50 AM
  3. Help with javascript, passing multiple select array to js then php
    By zen^Wallhack! in forum JavaScript Development
    Replies: 1
    Last Post: December 3rd, 2003, 01:56 PM
  4. Combine 3 SELECT statements - MySQL 3.23
    By amorgan in forum MySQL Help
    Replies: 1
    Last Post: December 1st, 2003, 05:21 PM
  5. Help with function to copy contents of select item
    By MilesDependent in forum HTML Programming
    Replies: 2
    Last Post: November 23rd, 2003, 06:16 PM

IMN logo majestic logo threadwatch logo seochat tools logo