Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP SUM Function...

  • 19-06-2007 06: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, Registered Users 2 Posts: 68,173 ✭✭✭✭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