Better way to load Mysql query in PHP Array
Regardless of how well you know the mysql_* functions, you shouldn't use them. There are counterparts within PDO. See this answer on stackoverflow for why.

This is how you'd do that in PDO:

$db = new PDO("mysql:localhost;dbname=database", $user, $password);

// set the default for -&gt;fetch() and -&gt;fetchAll() to associative array
$db-&gt;setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// throw an exception instead of an error on fail
$db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


try {
    $sql = "(select sum(p) / sum(w) * 100) as present from attendance group by month";

    // make sure you have php5-mysqlnd installed.
    // (MySQL native driver. It makes upgrading PHP easy as there's no library conflicts).
    // You can also work with different versions of MySQL without errors.
    $names = $db-&gt;query($sql)-&gt;fetchAll();

    // array_column will take an associative array and a key and flatten it into an array
    return array_column($names, "present");
} catch (PDOException $e) {
    echo "&lt;pre&gt;" . $e-&gt;getTraceAsString() . "&lt;/pre&gt;";
}


For error-handling, you should really use exceptions. Otherwise, check the value of $db-&gt;errorInfo()