SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql /PHP Adding two table rows together

    Help I'm stuck again!!

    I have a table in mysql database which has 3 fields, date ,bedsbooked and bookingid as the example below.



    date bedsbooked bookingid

    2008-12-01 6 1
    2008-12-04 4 3
    2008-12-04 8 7
    2009-01-04 2 10

    Booking id is obtained from joined table.

    date and bedsbooked are entered from a webpage taking booking details.

    From this I need to output the total number of beds booked for a specific date (ie. for 2008-12-04 it would be 4 + 8 =12) to one web page;

    bookingid date and bedsbooked (ie one line of table - easy!) to another web page.

    I can do the second page but am stuck with the first.

  2. #2
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT SUM(bedsbooked) FROM table WHERE date = '$date'";
    This should be in MySQL forum, by the way. (has been moved)

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    SELECT SUM(bedsbooked) AS total_bedsbooked
      FROM daTable
     WHERE `date` = '2008-12-04'
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2008
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Table didn't display very well first time.


    date | bedsbooked | bookingid

    2008-12-01 | 6 | 1
    2008-12-04 | 4 | 3
    2008-12-04 | 8 | 7
    2009-01-04 | 2 | 10


Bookmarks

Posting Permissions

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