Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP SUM Function...

Options
  • 19-06-2007 7:30pm
    #1
    Closed Accounts Posts: 7,097 ✭✭✭


    Hi all,

    I have a chunk of code that for love nor money will not work on my website. What I'm trying to do is really simple, just use the SUM function to add the numbers in a column in my database table and I'm getting a result "Query was empty" when I run the page...

    <?php
    $user="root";
    $password="orange;
    $database="table1";

    mysql_connect(localhost,$user,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT sum(subtotal) AS 'total_sub' FROM 'history' WHERE reg1='$car_reg1' AND reg2='$car_reg2' AND reg3='$car_reg3' AND status='$my_status'";

    $result = mysql_query($sql) or die(mysql_error());
    $l = mysql_fetch_array($result);
    echo $l;

    Can anyone see anything obviously wrong with this script???


Comments

  • Closed Accounts Posts: 7,097 ✭✭✭Darragh29


    Tis ok folks, I got it sorted! What is it about posting for advice that suddenly makes you see the problem!?!?


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    you get relaxed about it knowing that help is at hand.
    A 5 min. break helps as well.
    I had a similar think to do myself today that really got my brains worked out (sum from 3 tables), took a break for a cup of coffee and the solution came before I even got to make it.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Darragh29 wrote:
    Tis ok folks, I got it sorted! What is it about posting for advice that suddenly makes you see the problem!?!?
    :)

    It also happens when you ring a third-party support provider. You spend a week agonising over a problem, then you log a call with the vendor, and figure it out five minutes after they say they'll call you back :)


Advertisement