suchen
HeimBackend-EntwicklungPHP-Tutorial【php】三、学生管理系统-查看用户

【php】3、学生管理系统-查看用户

<?php include_once &#39;stuService.class.php&#39;;    session_start();    $name = $_SESSION[&#39;student_name&#39;];        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);    ?>		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	<title>学生成绩管理系统</title>				  
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; ?>
学生ID号 学生姓名 学生密码
"; //显示上一页和下一页 if($pagenow > 1) { $prePage=$pagenow - 1; echo "上一页   "; echo "《《   "; } echo ""; //中间打印10页选择 for($i=$pagenow; $i $i   "; } } echo ""; //下一页 if($pagenow 》》   "; echo "下一页   "; } echo ""; echo "当前页$pagenow/共{$pagecount}页面"; echo "
跳转到:


stuservice类

<?php //这个是对数据库中表student的操作    include_once &#39;mysql.class.php&#39;;    include_once &#39;student.class.php&#39;;    include_once &#39;confing.php&#39;;        class stuservice    {        //根据用户名和密码,查看个数        public function checkstunum($name, $password)        {            $mysql = new mysql(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);            $num=0;                        $sql = "select count(*) from student where stu_name = &#39;".$name."&#39; and stu_password = &#39;".$password."&#39;";            //执行命令            $res = $mysql->execute_dql($sql);            $row=mysqli_fetch_row($res);            if($row)            {                $num=$row[0];            }                        mysqli_free_result($res);            $mysql->close_connect();            return $num;                        }                //根据每页的大小,和当前的页面查询出所有的学生        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;        }                //得到总页数        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/$pagesize);    //返回不小于 value 的下一个整数,value 如果有小数部分则进一位。 			mysqli_free_result($res);			$mysql->close_connect();			return $pagecount;		}				//根据学生姓名得到相应数据		public function getstu($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->setStu_password($row['stu_password']);		    }		    		    mysqli_free_result($res);		    $mysql->close_connect();		    return $stu;		    		}				//根据id号获取user		public function getstubyid($id)		{		    $stu = new student();		    $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;		}				//根据得到的对象修改数据库中的值		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;		}				//删除用户		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类

<?php //     include_once &#39;confing.php&#39;;    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)		{	        parent::__construct($host, $user, $pass, $db);	    	        if (mysqli_connect_error()) {	            die(&#39;Connect Error (&#39; . mysqli_connect_errno() . &#39;) &#39;	                . mysqli_connect_error());	        }// 		    $this->link = new mysqli($this->db_host, $this->db_user, $this->db_password, $this->db_name);// 		    if(!$this->link){// 				die("连接失败".mysql_error());// 			}			//mysql_select_db($this->dbname,$this->link);		}				//执行SQL语句得到结果集,查询语句		public function execute_dql($sql)		{		    $res = $this->query($sql) or die(mysqli_error($this));		    return $res;		}				//执行SQLdml语句插入,更新,删除		public function execute_dml($sql)		{		    $b = $this->query($sql) or die(mysqli_error($this));		    if(!$b)		    {		        return 0;		    }		    else		    {		        if($this->affected_rows > 0)    //如果收影响的行数大于0		        {		            return 1; //OK了		        }		        else		        {		            return 2; //没有行收到影响		        }		    }		}				//关闭连接		public function close_connect()		{		    if(!empty($this))		        $this->close();		}    } ?>

student类

<?php class student    {        private $stu_id;        private $stu_name;        private $stu_password;      /**         * @return the $stu_id         */        public function getStu_id()        {            return $this->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配置数据库

<?php //用define定义常量	//连接服务器	define(&#39;DB_HOST&#39;, &#39;localhost&#39;);	//连接数据库的账号	define(&#39;DB_USER&#39;, &#39;root&#39;);	//连接数据库的密码	define(&#39;DB_PASSWORD&#39;, &#39;xiaofeng2015&#39;);	//连接数据库的名字	define(&#39;DB_NAME&#39;, &#39;studentmanage&#39;);	//?>	

预览:







Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
PHP -Leistungsstimmung für Websites mit hohem VerkehrPHP -Leistungsstimmung für Websites mit hohem VerkehrMay 14, 2025 am 12:13 AM

Thesecrettokeepingaphp-betriebene WebsiterunningSmoothyunderheavyLoadInvolvesseveralkeyStrategies: 1) ImplementoPCodeCachingWithopcachetoreducescholexexexcutiontime, 2) verwendetatabasequerycachingwithredolesendatabaSelaDaLoadaLoadaLoadaLoad, 3) LeveragecdnslikecloudLesendatabaselaSelaSelaSelaSelaSelaSelaSelaSelaSelaSeladinaSelaSelaSelaSelaSeladinaSelaSeladin

Abhängigkeitsinjektion in PHP: Code Beispiele für AnfängerAbhängigkeitsinjektion in PHP: Code Beispiele für AnfängerMay 14, 2025 am 12:08 AM

Sie sollten sich um die Abhängigkeitsinjektion (DI) kümmern, da Ihr Code klarer und leichter zu warten ist. 1) DI macht es modularer durch Entkopplung von Klassen, 2) verbessert die Bequemlichkeit von Tests und Code -Flexibilität, 3) DI -Container verwenden, um komplexe Abhängigkeiten zu verwalten, aber auf die Auswirkungen auf die Leistung und die kreisförmigen Abhängigkeiten zu achten, 4) Die beste Praxis besteht darin, sich auf abstrakte Schnittstellen zu verlassen, um lose Koupleln zu erreichen.

PHP -Leistung: Ist es möglich, die Anwendung zu optimieren?PHP -Leistung: Ist es möglich, die Anwendung zu optimieren?May 14, 2025 am 12:04 AM

Ja, optimizingaphpapplicationSispossiblandinential.1) ImplementCachingusedapcutoredatabaSeload.2) optimizedatabases-withindexing, effizienteQuerien und AnconnectionPooling.3) EnhanceCodewithbuilt-Infunktionen, Vermeidung von Globalvariablungen und UsusepcodeCodeCecess

PHP -Leistungsoptimierung: Der ultimative LeitfadenPHP -Leistungsoptimierung: Der ultimative LeitfadenMay 14, 2025 am 12:02 AM

TheKeyStrategieS significantBoostPhpapplicationPlicationperformanceare: 1) UseOpCodeCaching-likeopcachetoreduceExecutiontime, 2) optimizedatabaseInteractionswithprepararedStatements undProperIndexing, 3) configureWebserverSLIKENGINXWITHPHP-FPMFRMFRETBETTERPERSPRIGUNG, 4), 4), 4), 4), 4))

PHP -Abhängigkeitsinjektionsbehälter: Ein schneller StartPHP -Abhängigkeitsinjektionsbehälter: Ein schneller StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesClass -Abhängigkeiten, EnhancingCodemodularität, Testbarkeit und Maschinenbarkeit.

Abhängigkeitsinjektion im Vergleich zum Service -Locator in PHPAbhängigkeitsinjektion im Vergleich zum Service -Locator in PHPMay 13, 2025 am 12:10 AM

Wählen Sie die Abhängigkeitsinjektion (DI) für große Anwendungen. Der Servicelocator ist für kleine Projekte oder Prototypen geeignet. 1) DI verbessert die Testbarkeit und Modularität des Codes durch Konstruktorinjektion. 2) Servicelocator erhält Dienstleistungen durch die Zentrumregistrierung, was bequem ist, aber zu einer Erhöhung der Codekupplung führen kann.

PHP -Leistungsoptimierungsstrategien.PHP -Leistungsoptimierungsstrategien.May 13, 2025 am 12:06 AM

PhpapplicationscanbeoptimizedforspeedandefficiencyBy: 1) EnabgingOpcacheinphp.ini, 2) usePreparedStatementsWithpdoFordatabasequeries, 3) Ersatzloopswitharray_Filterandarray_mapfordataprozessing, 4) Konfigurieren von), 4), implementieren, 5)

PHP -E -Mail -Validierung: Stellen Sie sicher, dass E -Mails korrekt gesendet werdenPHP -E -Mail -Validierung: Stellen Sie sicher, dass E -Mails korrekt gesendet werdenMay 13, 2025 am 12:06 AM

PhpemailvalidationInvolvesthreesteps: 1) Formatvalidationusing -RegularexpressionStocheckTheemailformat; 2) DnsvalidationToensurethedomainhasavalidmxRecord;

See all articles

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem völlig kostenlosen KI-Gesichtstausch-Tool aus!

Heißer Artikel

Nordhold: Fusionssystem, erklärt
4 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
Mandragora: Flüstern des Hexenbaum
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Dreamweaver Mac

Dreamweaver Mac

Visuelle Webentwicklungstools

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

SublimeText3 Linux neue Version

SublimeText3 Linux neue Version

SublimeText3 Linux neueste Version

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

SAP NetWeaver Server-Adapter für Eclipse

SAP NetWeaver Server-Adapter für Eclipse

Integrieren Sie Eclipse mit dem SAP NetWeaver-Anwendungsserver.