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 4 of 4

Thread: sql

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    sql

    Hi

    Im trying to find the highest id in the primary key Product_ID in the database and assign it to a variable.
    The sql brings back the correct result
    But when i use it in php i get no result

    Can anyone see whats wrong with this code??
    Thanks

    $query = "SELECT max(Product_ID) as MaxID from Prods";
    $result = @mysql_query($query) or die(mysql_error());


    while($row = @mysql_fetch_array($result))
    {
    echo $row['Product_ID'];
    }

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Need to change the $row variable as you are using the AS to give it an alias in your query ..

    change your code from
    echo $row['Product_ID'];
    to
    echo $row['MaxID];
    and you should be good

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    of course i feel silly now!!
    thanks

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    anytime


  •  

    Posting Permissions

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