Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use mysql limit function in php to find last record

    IT IS NOT WORKING , CAN SOMEONE HELP.



    $SQLDISTRIBUTOR = " SELECT * FROM DISTRIBUTOR ";
    $SQLDISTRIBUTOR.= " WHERE COUNTRYCOD =" . $_SESSION['COUNTRYCOD'];
    $SQLDISTRIBUTOR.= " AND STATECOD =" . $_SESSION['STATECOD'];
    $SQLDISTRIBUTOR.= " AND CITYCOD =" . $_SESSION['CITYCOD'];
    $SQLDISTRIBUTOR.= " ORDER BY ACCOUNT_NUMBER DESCENDING LIMIT 1 ";
    $FDISTRIBUTOR = mysql_query( $SQLDISTRIBUTOR, $CON );

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    WHAT is not working???
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jul 2010
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    whenever I make the object

    CREDITOR =mysql_fetch_object(($FDISTRIBUTOR)
    and access a property (data field) I get error message

    trying to get property of a non object.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Is DESCENDING valid? I can't test that where I am, but its not listed as a sort option in the mysql documentation. Assuming its not, attempting to query that would result in a sql syntax error and fail the query.
    PHP wise you need to verify your resources before using them:
    PHP Code:
    if ( $FDISTRIBUTOR mysql_query$SQLDISTRIBUTOR$CON ))
    {
        
    // now you can do whatever
    }
    else
    {
        die(
    mysql_error($CON));

    Note as well that the mysql library is deprecated and will be removed in a future version.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,155
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Ahhh...good catch, FouLu. NO. MySQL does *NOT* allow DESCENDING (I think SQL Server does). You must use just DESC and ASC
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •