SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2010
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysqli_fetch_row problem

    Hi again all

    I am hoping you can assist with a problem I am having. I am trying to get the 'sum' of a couple of columns in noe of my tables. I am using the following code:

    PHP Code:
        $sqltotal 'SELECT sum(net), sum(vat), sum(gross) FROM invoice INNER JOIN property'$where;
        
        echo 
    'SQL Total = '.$sqltotal;
        
    $total mysqli_query($link$sqltotal);

        
    $resulttotal mysqli_fetch_row($link$total); 
    To explain a little $where can vary depending on search criteria.

    The MySQL works, whenI enter it direct into the database ( It returns the 3 values I want)

    However, when I try and get the same result using mysqli_fetch_row, I get the error message:

    Warning: mysqli_fetch_row() expects exactly 1 parameter, 2 given in ***********

    I know the DB Connection works fine.

    I've been staring at this for too long and going about in circles, if anyone can assist I would be extremely grateful!

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    I'm no mysqli user but the manual suggests:
    PHP Code:
    mysqli_fetch_row($total); 
    BTW assigning a var for each sum might make things easier to understand further into your app.
    PHP Code:
    $sqltotal 'SELECT sum(net) as t_net, sum(vat) as t_vat, sum(gross) as t_gross FROM invoice INNER JOIN property'$where
    Now sure where the $where values are coming from or what they contain but you could should familiarise yourself with the numerous benefits of using Mysqli's prepared statements too.


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
  •