"PHP" 3, Student management system-View users

Source: Internet
Author: User
Tags php class rowcount

<?php include_once ' stuService.class.php ';    Session_Start ();        $name = $_session[' student_name ');        if ($name = = "") {header ("location:stu_login.php?error=1");    Exit ();    } $pagesize = 20;    $pagenow = 1;    $pagecount = 0;    $service = new Stuservice ();    $pagecount = $service->getpagecount ($pagesize);    if (!empty ($_get[' Pagenow ')) {$pagenow =$_get[' pagenow '];    } $stulist = $service->getstulist ($pagesize, $pagenow); ? ><! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">


Stuservice class

<?php//This is the operation of the table student in the database include_once ' mysql.class.php ';    Include_once ' student.class.php ';        Include_once ' confing.php '; Class Stuservice {//Based on user name and password, view the number of public function checkstunum ($name, $password) {$mys            QL = new MySQL (db_host, Db_user, Db_password, db_name);                        $num = 0;            $sql = "SELECT count (*) from student where Stu_name = '". $name. "' and Stu_password = '". $password. "'";            Execute command $res = $mysql->execute_dql ($sql);            $row =mysqli_fetch_row ($res);            if ($row) {$num = $row [0];            } mysqli_free_result ($res);            $mysql->close_connect ();                        return $num;  }//According to the size of each page, and the current page query out all the student public function getstulist ($pagesize, $pagenow) {$mysql                        = new MySQL (db_host, Db_user, Db_password, db_name); $sql = "SELECT * FROM StUdent limit ".            ($pagenow-1) * $pagesize. ", $pagesize";                        $res = $mysql->execute_dql ($sql);                        $arr =array ();                        $i = 0;            while ($row = Mysqli_fetch_assoc ($res)) {$arr [$i ++]= $row;            } mysqli_free_result ($res);            $mysql->close_connect ();        return $arr; }//Get total pages Public Function Getpagecount ($pagesize) {$mysql = new MySQL (db_host, Db_user, DB_PA ssWOrd, db_name); $sql = "SELECT count (stu_id) from student"; $res = $mysql->execute_dql ($sql); $i =0; $row = Mysqli_fetch _row ($res), if ($row) {$rowcount = $row [0];}    $pagecount =ceil ($rowcount/$pagesize); Returns the next integer not less than value, in which value is entered if there is a fractional part. Mysqli_free_result ($res); $mysql->close_connect (); return $pagecount;}    The corresponding data public function Getstu ($name) {$stu = new student () is obtained according to the student's name;    $mysql = new MySQL (db_host, Db_user, Db_password, db_name); $sql = "SELECT * FROM student where Stu_name= ' ". $name." ";        $res = $mysql->execute_dql ($sql);        if ($row = Mysqli_fetch_assoc ($res)) {$stu->setstu_id ($row [' stu_id ']);        $stu->setstu_name ($row [' stu_name ']);    $stu->setstu_password ($row [' Stu_password ']);    } mysqli_free_result ($res);    $mysql->close_connect ();    return $stu;    }//gets Userpublic function Getstubyid ($id) {$stu = new student () according to the ID number;    $mysql = new MySQL (db_host, Db_user, Db_password, db_name);    $sql = "SELECT * from student where stu_id= '". $id. "'";        $res = $mysql->execute_dql ($sql);        if ($row = Mysqli_fetch_assoc ($res)) {$stu->setstu_id ($row [' stu_id ']);        $stu->setstu_name ($row [' stu_name ']);    $stu->setstu_password ($row [' Stu_password ']);    } mysqli_free_result ($res);    $mysql->close_connect (); return $stu;}    Modify the values in the database according to the resulting object public function update (student $stu) {$mysql = new MySQL (db_host, Db_user, Db_password, db_name); $sql = "Update student set Stu_Name= '. $stu->getstu_name (). "', stu_password= '". $stu->getstu_password (). "'        Where stu_id= ". $stu->getstu_id (); $b = $mysql->execute_dml ($sql),//if ($b = = 1)//{//Return true;//} return $b;}    Delete User Public Function Delete (student $stu) {$mysql = new MySQL (db_host, Db_user, Db_password, db_name);    $sql = "Delete from student where stu_id=". $stu->getstu_id (). ";";        $b = $mysql->execute_dml ($sql);    return $b;} }?>

MySQL class

<?php//include_once ' confing.php ';  Class MySQL extends Mysqli {//Public $link,//public $db _host = db_host;//public $db _user = db_user;//Public $db _password = db_password;//public $db _name = db_name;public function __construct ($host, $user, $pass, $db) {par            Ent::__construct ($host, $user, $pass, $db); if (Mysqli_connect_error ()) {die (' Connect error ('. Mysqli_connect_errno () '). ') '                .        Mysqli_connect_error ());     }//$this->link = new Mysqli ($this->db_host, $this->db_user, $this->db_password, $this->db_name);// if (! $this->link) {//Die ("Connection Failed". Mysql_error ());//}//mysql_select_db ($this->dbname, $this->link);}    Execute SQL statement to get result set, query statement public Function EXECUTE_DQL ($sql) {$res = $this->query ($sql) or Die (Mysqli_error ($this)); return $res;}    Execute SQLDML statement INSERT, UPDATE, delete public function execute_dml ($sql) {$b = $this->query ($sql) or Die (Mysqli_error ($this));    if (! $b) {return 0; }   else {if ($this->affected_rows > 0)//If the number of rows affected is greater than 0 {return 1;//ok}        else {return 2;//No rows received affected}}}//close connection public Function Close_connect () {if (!empty ($this))    $this->close ();} }?>

Student class

<?php class Student {private $stu _id;        Private $stu _name;      Private $stu _password; /** * @return The $stu _id */Public Function getstu_id () {return $this->stu_i        D }/** * @return the $stu _name */Public Function Getstu_name () {return        $this->stu_name;            }/** * @return the $stu _password */Public Function Getstu_password () {        return $this->stu_password;            }/** * @param field_type $stu _id */Public Function setstu_id ($stu _id) {        $this->stu_id = $stu _id;            }/** * @param field_type $stu _name */Public Function setstu_name ($stu _name) {        $this->stu_name = $stu _name; }/** * @param field_type $stu _password */Public Function Setstu_password ($stu _PAssWOrd) {$this->stu_password = $stu _password;     }}?>

config.php Configuration Database

<?php//use define to define constants//connection server define (' db_host ', ' localhost '),///Connect the database to the account define (' Db_user ', ' root ');//Connect the database password define ( ' Db_password ', ' xiaofeng2015 ');//Connection database name define (' Db_name ', ' studentmanage ');//?>

Preview:







"PHP" 3, Student management system-View users

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.