• Hi,

    I’m trying to do a simple sum query based on category but what ever i try does not work.


    $wpdb->wpfb_files = $wpdb->prefix . ‘wpfb_files’;

    $total_hits = $wpdb->get_var( “SELECT SUM(file_hits) FROM $wpdb->wpfb_files WHERE file_category = 2″ );”

    It didn’t even work without the Where.

    How would you go about doing this?

    thanks,
    Kennyist.

    [No Bumping]

Viewing 1 replies (of 1 total)
  • Let’s first get the raw SQL for debugging…

    $wpdb->wpfb_files = $wpdb->prefix . 'wpfb_files';
    
    $sql = "SELECT SUM(file_hits) FROM $wpdb->wpfb_files WHERE file_category = 2" ;
    
    $total_hits = $wpdb->get_var( $sql );
    
    echo "SQL: $sql<br/>";

    With the output, run the SQL query manually (eg. phpmyadmin), and see what you get.

    Try replacing SUM(file_hits) with just file_hits in the query above as well.

    Cheers!

Viewing 1 replies (of 1 total)

The topic ‘Mysql querys help’ is closed to new replies.