[Php] 3. student management system-View Users

Source: Internet
Author: User
[Php] 3. student management system-View Users & lt ;? Phpinclude_once & #39; stuService. class. php & #39; session_start (); $ name $ _ SESSION [& #39; student_name & #39;]; if ($ name & quot ;) {[php] 3. student management system-View Users
 Getpagecount ($ pagesize); if (! Empty ($ _ GET ['pagenow']) {$ pagenow = $ _ GET ['pagenow'];} $ stulist = $ service-> getstulist ($ pagesize, $ pagenow);?>
 Student achievement management system  


Stuservice class

 Execute_dql ($ SQL); $ row = mysqli_fetch_row ($ res); if ($ row) {$ num = $ row [0];} mysqli_free_result ($ res ); $ mysql-> close_connect (); return $ num;} // query all students public function getstulist ($ pagesize, $ pagenow) based on the size of each page and the current page) {$ 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; w Hile ($ row = mysqli_fetch_assoc ($ res) {$ arr [$ I ++] = $ row;} mysqli_free_result ($ res); $ mysql-> close_connect (); return $ arr;} // obtain the total number of pages public function getpagecount ($ pagesize) {$ mysql = new mysql (DB_HOST, DB_USER, DB_PASSWORD, 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/$ pages Ize); // return the next integer not less than value. if the value has a decimal part, it is entered. Mysqli_free_result ($ res); $ mysql-> close_connect (); return $ pagecount;} // obtain the corresponding public function getstu ($ name) based on the student name) {$ stu = new student (); $ 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-> se TStu_password ($ row ['Stu _ password']);} mysqli_free_result ($ res); $ mysql-> close_connect (); return $ stu ;} // Obtain userpublic function getstubyid ($ id) {$ stu = new student (); $ mysql = new mysql (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) based on the id number ); $ 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 public function update (student $ stu) in the database based on the obtained object {$ 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

 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);} // run the SQL statement to obtain the 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, and 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 by the receipt is greater than 0 {return 1; // OK} else {return 2; // no rows have been affected} // close the connection to public function close_connect () {if (! Empty ($ this) $ this-> close () ;}}?>

Student class

 stu_id;        }          /**         * @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

 

Preview:







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.