当前位置: 首页>>代码示例>>PHP>>正文


PHP StudentInfo::firstName方法代码示例

本文整理汇总了PHP中StudentInfo::firstName方法的典型用法代码示例。如果您正苦于以下问题:PHP StudentInfo::firstName方法的具体用法?PHP StudentInfo::firstName怎么用?PHP StudentInfo::firstName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StudentInfo的用法示例。


在下文中一共展示了StudentInfo::firstName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: studentSignin

function studentSignin($pdo)
{
    $student_info = new StudentInfo();
    //$student_id = $student_info->generateId();
    $fname = $student_info->firstName();
    $lname = $student_info->lastName();
    session_unset();
    $query = "SELECT * FROM student WHERE student_fname = :fname AND student_lname = :lname";
    $stmt = $pdo->prepare($query);
    $stmt->bindParam(':fname', $fname);
    $stmt->bindParam(':lname', $lname);
    $stmt->execute();
    if ($student_exists = $stmt->fetch()) {
        foreach ($student_exists as $student) {
            $_SESSION['user_id'] = $student['student_id'];
            $_SESSION['f_name'] = $student['student_fname'];
            $_SESSION['l_name'] = $student['student_lname'];
            $_SESSION['theme'] = "red";
            $_SESSION['rank'] = 1;
        }
    } else {
        $student_id = $student_info->generateId();
        $_SESSION['user_id'] = $student_id;
        $_SESSION['f_name'] = $fname;
        $_SESSION['l_name'] = $lname;
        $_SESSION['theme'] = "red";
        $_SESSION['rank'] = 1;
        $query = "INSERT INTO student (student_id, student_fname, student_lname) VALUES (:student_id, :fname, :lname)";
        $stmt = $pdo->prepare($query);
        $stmt->bindParam(':student_id', $student_id, PDO::PARAM_INT);
        $stmt->bindParam(':fname', $fname);
        $stmt->bindParam(':lname', $lname);
        $stmt->execute();
        //$course_id = rand(1,3);
        $query = "SELECT * FROM class";
        // This part can just be replaced with a COUNT function
        $stmt = $pdo->prepare($query);
        $stmt->execute();
        $num_classes = $stmt->rowCount();
        $classes_enrolled = array();
        $classes_enrolled[0] = rand(1, 3);
        while (($i = rand(1, 3)) == $classes_enrolled[0]) {
        }
        $classes_enrolled[1] = $i;
        while (($i = rand(1, 3)) == $classes_enrolled[0] || $i == $classes_enrolled[1]) {
        }
        $classes_enrolled[2] = $i;
        for ($i = 0; $i < 3; $i++) {
            $query = "INSERT INTO enroll (enroll_student_id, enroll_class_id) VALUES (:student_id, :course_id)";
            $stmt = $pdo->prepare($query);
            $stmt->bindParam(':student_id', $student_id);
            $stmt->bindParam(':course_id', $classes_enrolled[$i]);
            $stmt->execute();
        }
    }
    $pdo = null;
}
开发者ID:JosephsPlace,项目名称:Ocena,代码行数:57,代码来源:functions.php

示例2: studentSignin

function studentSignin()
{
    try {
        $pdo = new PDO(DB_PDODRIVER . ':host=' . DB_HOST . ';dbname=' . DB_NAME . '', DB_USER, DB_PASS);
    } catch (\PDOException $e) {
        echo "Connection failed: " . $e->getMessage();
        exit;
    }
    $student_info = new StudentInfo();
    //$student_id = $student_info->generateId();
    $fname = $student_info->firstName();
    $lname = $student_info->lastName();
    session_unset();
    $query = "SELECT * FROM student WHERE student_fname = :fname AND student_lname = :lname";
    $stmt = $pdo->prepare($query);
    $stmt->bindParam(':fname', $fname);
    $stmt->bindParam(':lname', $lname);
    $stmt->execute();
    if ($stmt->fetch(PDO::FETCH_ASSOC)) {
        while ($student = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $_SESSION['user_id'] = $student['student_id'];
            $_SESSION['f_name'] = $student['student_fname'];
            $_SESSION['l_name'] = $student['student_lname'];
            $_SESSION['theme'] = "red";
            $_SESSION['rank'] = 1;
        }
    } else {
        $student_id = $student_info->generateId();
        $_SESSION['user_id'] = $student_id;
        $_SESSION['f_name'] = $fname;
        $_SESSION['l_name'] = $lname;
        $_SESSION['theme'] = "red";
        $_SERVER['rank'] = 1;
        $query = "INSERT INTO student (student_id, student_fname, student_lname) VALUES (:student_id, :fname, :lname)";
        $stmt = $pdo->prepare($query);
        $stmt->bindParam(':student_id', $student_id, PDO::PARAM_INT);
        $stmt->bindParam(':fname', $fname);
        $stmt->bindParam(':lname', $lname);
        $stmt->execute();
        //$course_id = rand(1,3);
        $query = "SELECT * FROM class";
        // This part can just be replaced with a COUNT function
        $stmt = $pdo->prepare($query);
        $stmt->execute();
        $num_classes = $stmt->rowCount();
        $classes_enrolled = array();
        $classes_enrolled[0] = rand(1, 3);
        while (($i = rand(1, 3)) == $classes_enrolled[0]) {
        }
        $classes_enrolled[1] = $i;
        while (($i = rand(1, 3)) == $classes_enrolled[0] || $i == $classes_enrolled[1]) {
        }
        $classes_enrolled[2] = $i;
        for ($i = 0; $i < 3; $i++) {
            $query = "INSERT INTO enroll (enroll_student_id, enroll_class_id) VALUES (:student_id, :course_id)";
            $stmt = $pdo->prepare($query);
            $stmt->bindParam(':student_id', $student_id);
            $stmt->bindParam(':course_id', $classes_enrolled[$i]);
            $stmt->execute();
        }
    }
    $pdo = null;
}
开发者ID:paul-sei2015,项目名称:Ocena,代码行数:63,代码来源:functions.php


注:本文中的StudentInfo::firstName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。