SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  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,631
    Mentioned
    2 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 gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 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?
    rudy.ca | @rudydotca
    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
  •