PHP - 显示选择该项目的人数?

时间:2014-06-05 15:41:17

标签: php mysql

我的网站是针对我的学校的,我们正在创建一个登录页面,显示已注册特定课程的学生数量。

我对如何让它发挥作用感到困惑。每当有人选择一个类时,它应该告诉数据库一个人选择该特定类。然后我会回应说这很多人选择了那个班级。

我为$学生创建了一个变量,还添加了一个表格'学生'在数据库中。我还遇到了麻烦。这是我的代码。我在每个时期都回应着学生。

$names = $db->fetchAll("select `name` from `classes`");

$login = $_POST['login'];
$username = $_POST['username'];
$password = $_POST['password'];
$fname = $_POST['fname'];
$update = $_POST['update'];
$lname = $_POST['lname'];
$gender = $_POST['gender'];
$email = $_POST['email'];
$pic = $_POST['pic'];
$created_on = $_POST['created_on'];

$per1 = $_POST['per1'];
$per2 = $_POST['per2'];
$per3 = $_POST['per3'];
$per4 = $_POST['per4'];
$per5 = $_POST['per5'];
$per6 = $_POST['per6'];
$per7 = $_POST['per7'];
$month = $_POST['month'];
$day = $_POST['day'];
$year = $_POST['year'];
$logged_in = $_COOKIE['logged_in'];

$bday = "$month $day $year";
$students = $_POST['students'];

if (empty($logged_in) ) {
    header("location: login.php");
}

$info = $db->fetchRow("select * from `profile` 
                       where `username` =?", array($logged_in));

if ($update == "Update"){
    $data = array(
        'fname' => $fname,
        'lname' => $lname,
        'email' => $email,
        'gender' => $gender,
        'pic' => $pic,
        'per1' => $per1,
        'per2' => $per2,
        'per3' => $per3,
        'per4' => $per4,
        'per5' => $per5,
        'per6' => $per6,
        'per7' => $per7,
        'bday' => $bday,
        'students' => $students
    );

    $db->update($data, "profile", "id=?", array($info['id']));
}

$info = $db->fetchRow("select * from `profile` 
                       where `username` =?", array($logged_in));

0 个答案:

没有答案