SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_fetch_array problem

    I am trying to get the total sum of some values from my db, my code below just outputs "Array" and not the actual numbers.. any ideas?

    PHP Code:
    $query_c1 "SELECT SUM(order_price) AS total_price FROM orders WHERE charity_coupons_code = 'test1'";
                                                
    $dbc1 mysqli_connect('localhost''yellowb_user','data123','yellowb_data');
                                                
    $data=array();
                                                
    $db_charity mysqli_query($dbc1,$query_c1);                                            
                                                while(
    $row=    mysqli_fetch_array($db_charity)) {
                                                   
    $data[] = $row[0];
                                                }                                            
                                                echo 
    $data

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    because... $data is an array.
    print_r($data) instead.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just changed it but now it output is:

    Array ( [0] => )

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Try print_r 'ing $row inside the loop.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now its outputing this

    Array ( [0] => )

  6. #6
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $data = array();
    while(
    $row=    mysqli_fetch_array($db_charity)) {
        
    array_push ($data,$row[0]);
    }
    print_r $data
    As above, may be used.


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
  •