Hi,

I am using PHP and MySQL and I was wondering if anyone knew how to 'drop' the last record retrieved from a SELECT query. Or just not retrieve it?.

I am trying to retrieve all of the records in a table EXCEPT the very last one. I could do it with a LIMIT but the database will grow so I don't know what the last records will be.

Any hep would be very much appreciated.

Many thanks,

theUKdude

    Seems like this would work when you retrieve your results in PHP, of course assuming you have an "ORDER BY" an auto-incremented field:

    while ($row=mysql_fetch_object($dbResult))
    {
    $whatever[]=$row->whatever;
    }
    $whatever_pop = array_pop($whatever);

    //this will "pop" the last value off the end of the array. Basically you are building an array from your results and then using the function to take the last value off the array. (This is just one possible way, I am sure there are tons of different ways that this can be accomplished!)

    -Hopes this helps

      Write a Reply...