+ Reply to Thread
Results 1 to 4 of 4

Thread: PHP and MYSQL Help

  1. #1
    stesouthby is offline x10 Sophmore stesouthby is an unknown quantity at this point
    Join Date
    Sep 2009
    Location
    UK
    Posts
    115

    Thumbs up PHP and MYSQL Help

    Hi I have a transaction database where when you up date the traction of a product it is place on the that as like 200 or -50 and it carrys on like this in a list I was wondering what code would i need to do to add all the mysql tranactions up to get a total and place it on in a products table or displays it on the home page any help would be greatful i know i will need to do a mysql query to get all the ones i need i just don't know where to go from there
    "It's time to prove to your friends that you're worth a damn. Sometimes that means dying, sometimes it means killing a whole lot of people."- sin city "You either die a hero or you live long enough to see yourself become the villain" - TDK

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP and MYSQL Help

    What?
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    stesouthby is offline x10 Sophmore stesouthby is an unknown quantity at this point
    Join Date
    Sep 2009
    Location
    UK
    Posts
    115

    Thumbs up Re: PHP and MYSQL Help

    ok right if you have a list of numbers in a mysql database is the away to add and subtract them all to get a total for example if it would be listed as ethier 20 or -20 is there away to do that?
    "It's time to prove to your friends that you're worth a damn. Sometimes that means dying, sometimes it means killing a whole lot of people."- sin city "You either die a hero or you live long enough to see yourself become the villain" - TDK

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP and MYSQL Help

    SQL has aggregate functions that operate on grouped columns, returning a single value for the group. In this case, SUM should do what you want.

    Code:
    SELECT SUM(delta) FROM transactions GROUP BY product;
    If you need something more specific, you'll need to include a minimal test case, which (for this question) would be a table schema (definition) and test data. For example,

    Code:
    CREATE TABLE transactions (
        id INT PRIMARY KEY AUTO_INCREMENT,
        delta INT,
        product INT /* REFERENCES products (id) ON DELETE CASCADE ON UPDATE CASCADE */,
    ) Engine=InnoDB;
    
    INSERT INTO transactions (delta, product)
      VALUES
        (20, 0),
        ...
      ;
    Also, this.
    Last edited by misson; 09-14-2010 at 07:11 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 02-01-2010, 05:45 AM
  2. mySQL error - argument is not a valid MySQL result resource
    By Awesomexr in forum Programming Help
    Replies: 3
    Last Post: 12-20-2009, 04:12 PM
  3. Replies: 3
    Last Post: 02-14-2008, 01:38 PM
  4. Replies: 2
    Last Post: 12-17-2007, 03:00 AM
  5. Replies: 2
    Last Post: 11-20-2007, 11:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers