Search code examples
phpmysqlsumecho

Echo SUM from mysql


<?php $q = $this->db->query("select SUM(pocet_dni) as pocet from holiday where teacher_id="._get_current_user_id($this));
                                 $pocet_dni = $row['pocet'];
                                    echo $pocet;
               ?>

I can not echo SUM. What is wrong?


Solution

  • $pocet does not exists. Use row_array().

    $q = $this->db->query("select SUM(pocet_dni) as pocet from holiday where teacher_id="._get_current_user_id($this))->row_array();
    $pocet = $q['pocet'];
    echo $pocet;