vendredi 29 mai 2015

search and count by gender and race

I just want to know any ideas for me to find gender and race. The data should display like:

-----------------------------
course  | Race 1 | Race 2 | 
        | M | F  | M | F  |
-----------------------------
science | 2 | 4  | 3 | 7  |

//this is table structure

$sql = "CREATE TABLE student (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
name VARCHAR(30) NOT NULL,
gender VARCHAR(30) NOT NULL,
race VARCHAR(50),
session VARCHAR(50),
course VARCHAR(50),
)";

The code that I already have:

<?php
include "connect_db.php";
if ((isset($_POST['submit'])) AND ($_POST['search'] <> "")) {

    $search = $_POST['search'];

    $sql = "SELECT gender, count(gender) AS cnt FROM student WHERE session LIKE '%$search%' AND gender IN ('Male', 'Female') GROUP BY gender" or die(mysqli_error(
        ''
    ));
    $result = $conn->query($sql);

    while ($row = fetch_assoc($result)) {
        $dataSet->addPoint(new Point($row['gender'], $row['cnt']));

    }

}

Aucun commentaire:

Enregistrer un commentaire