SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: How to calculate all data from array list from the database

  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Location
    Lagos, NIgeria
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to calculate all data from array list from the database

    I just tried to develop a small e-commerce site, i used database to store the shopping information for a paticular customer... BUt i need to calculate the total price order a that particular time.


    i was able to fetch the particular product but need to calculate the total cost can anyone help me out.

    example:

    PHP Code:
    $sql=$cc->query("SELECT * FROM temp_order where uname='$uname' ");

    while(
    $fet=$cc->fetch($sql)){

    $user=$fet['uname'];
    $product_price=$fet['product_price'];

    User                Price
    $uname          $product_price
    }
     
                         
    Total:(??);//need to get the total here. 
    Knowledge+application=power
    Unleashed Solution

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,534
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    SELECT *, SUM(product_price) AS Total FROM temp_order where uname='$uname'
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,453
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    not quite right, ian, since with all those non-aggregates (the evil "select star") you are missing the GROUP BY clause

    skima, what does "fetch the particular product" mean? if there's only one product, why do you need to compute a total? does this imply that there is actually more than one product? and if you do require details (i.e. more than one product), then why couldn't php be used to calculate their total? or do youi want just the total and not the products?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

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
  •