PHP + HTML simple BBS forum and Reply

Source: Internet
Author: User
Tags php define
PHP + HTML simple implementation BBS forum and reply this article mainly describes how to use PHP + HTML to simple implementation of BBS forum and post/reply functions, which is part of our php project. The main content includes:
1. use JavaScript and Iframe to implement the local layout interface
2. how does PHP define classes to implement database access?
3. implement simple BBS forum and post/reply functions
As this project was completed by ten people during the winter vacation, SAE was used to build an online back-end database. others were using Apache to locally design webpages and access databases, it is equivalent to a simple BS three-end access.
Source code:
Access http: // localhost: 8080/testphp/index. php is shown in:




I. homepage layout construction

The first step is to build the homepage layout, which includes head, main_left, and main_right. The display on the right is partial display implemented by iframe, while the click hide and display functions are implemented by JavaScript on the left. The index. php homepage code is as follows:

 Distributed System excellent course learning
 
 

You have not logged on! | Login | student registration | instructor registration

Here, the csscode deployment is implemented using mycss.css in the CSS file:
Html, body {height: '000000'; width: '000000';}/* head layout */# main {margin-left: 200px; width: 950px ;} /* central layout */# middle {width: 950px; height: 500px; background-color: # b6effa;}/* left of central area */# index_left {float: left; margin-top: 10px; margin-left: 10px; width: 180px; height: 480px;}/* middle right side */# index_right {float: right; margin-top: 10px; margin-right: 20px; width: 720px; height: 480px; border-style: double;}/* middle right side */# logout_middle {float: right; margin-top: 100px; margin-right: 220px; width: 500px; height: 300px; border-style: double; background-color: # ffffff ;}
The main code in Iframe is When called, the "BBS forum" declares that the target is rightFrame. At the same time, hide the display settings style. display as block or none. &lt;Br/&gt; The main_left.php code is as follows. &lt;Br/&gt; &lt;pre name = "code" class = "sycode"&gt; &lt;! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"&gt; &lt;HTML&gt; &lt;HEAD&gt; &lt;META http-equiv = Content-Type content = "text/html; charset = utf-8 "&gt; &lt;LINK href =" css/admin.css "type =" text/css "rel =" stylesheet "&gt; &lt;SCRIPT language = javascript&gt; function expand (el) {childObj = document. getElementById ("child" + el); if (childObj. style. display = 'none') {childObj. style. display = 'block';} else {childObj. style. display =' None ';} return ;} SCRIPT &lt;/HEAD&gt; &lt;BODY&gt; &lt;TABLE height = "100%" cellSpacing = 0 cellPadding = 0 width = 170 background = images/menu_bg.jpg border = 0 align = left&gt; &lt;TR&gt; &lt;TD vAlign = top align = middle&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = "100%" border = 0&gt; &lt;TR&gt; &lt;TD height = 10&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;! -- Option 1 --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = 150 border = 0&gt; &lt;TR height = 30&gt; &lt;TD style = "PADDING-LEFT: 20px; FONT-SIZE: 15px "background = images/menu_bt.jpg&gt; course homepage &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 4&gt; &lt;TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;TABLE id = child1 style = "DISPLAY: none "cellSpacing = 0 cellPadding = 0 width = 150 border = 0&gt; &lt;TR height = 20&gt; &lt;TD align = middle width = 30&gt; &lt;/TD&gt; &lt;TD&gt; homepage introduction &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 4&gt; &lt;TD colSpan = 2&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;! -- Option 2 --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = 150 border = 0&gt; &lt;TR height = 30&gt; &lt;TD style = "PADDING-LEFT: 20px; FONT-SIZE: 15px "background = images/menu_bt.jpg&gt; Course Overview &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 4&gt; &lt;TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;TABLE id = child2 style = "DISPLAY: none "cellSpacing = 0 cellPadding = 0 width = 150 border = 0&gt; &lt;TR height = 20&gt; &lt;TD align = middle width = 30&gt; &lt;/TD&gt; &lt;TD&gt; course introduction &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 20&gt; &lt;TD align = middle wid Th = 30&gt; &lt;/TD&gt; &lt;TD&gt; Instructor Team &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 20&gt; &lt;TD align = middle width = 30&gt; &lt;/TD&gt; &lt;TD&gt; teaching conditions &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 4&gt; &lt;TD colSpan = 2&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;! -- Option 3 --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = 150 border = 0&gt; &lt;TR height = 30&gt; &lt;TD style = "PADDING-LEFT: 20px; FONT-SIZE: 15px "background = images/menu_bt.jpg&gt; Interactive communication &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 4&gt; &lt;TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;TABLE id = child3 style = "DISPLAY: block "cellSpacing = 0 cellPadding = 0 width = 150 border = 0&gt; &lt;TR height = 20&gt; &lt;TD align = middle width = 30&gt; &lt;/TD&gt; &lt;TD&gt; BBS Forum &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 20&gt; &lt;TD align = middle Width = 30&gt; &lt;/TD&gt; &lt;TD&gt; Notification announcement &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 4&gt; &lt;TD colSpan = 2&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;/BODY&gt; &lt;/HTML&gt; &lt;/pre&gt;: &lt;br/&gt; &lt;p class = "sycode"&gt; &lt;/p&gt; &lt;p class = "sycode"&gt; &lt;br/&gt; &lt;/p&gt; &lt;p class = "sycode"&gt; II. to implement BBS forums and reply to forums, you can use Httppost in the custom database folder. php implementation, where the main_right3-1.php is to display all BBS forum posts the topic, and the main_right3-1-content.php is the corresponding post content, including the reply content. &lt;Br/&gt; The main_right3-1.php code is as follows: &lt;/p&gt; &lt;p class = "sycode"&gt; &lt;pre name = "code" class = "sycode"&gt; &lt;? Phpheader ("Content-Type: text/html; charset = utf-8"); // Note: include a php file cannot be repeated. recursively check whether repeated include (".. /database/httppost. php ");?&gt; &lt;! -- Note that in Html, "indicates returning to the upper-level directory, and css is the same directory as the main_right3-1.php --&gt; &lt;link rel =" stylesheet "href =" css/main.css "type =" text/css "/&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = "100%" align = center border = 0&gt; &lt;TR height = 28&gt; &lt;TD&gt; Current location: BBS Forum &lt;/TD&gt; &lt;TD align = right&gt; back &lt;/TD&gt; &lt;/TR&gt; &lt;TD bgColor = # b1ceef height = 1 colspan = "2"&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 10&gt; &lt;TD background = images/shadow_bg.jpg colspan = "2"&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;p cl Ass = "middle"&gt; &lt;p class = "wrap"&gt; &lt;p class = "wrap_left"&gt; &lt;p class = "wenda-head"&gt; latest popularity awaiting reply &lt;/p&gt; &lt;? Php // query paste $ hgi = new HttpPostInf (); $ result = $ hgi-&gt; doquery ('2', "select * from BBS_Post ;"); // parse json $ dj = json_decode ($ result, true); $ jcount = count ($ dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {?&gt; &lt;P class = "wenda-list"&gt; &lt;p class = "headslider"&gt; &lt;? Php echo $ dj [$ I] ['BP _ Pid '];?&gt; &lt;/P&gt; &lt;p class = "qaslider"&gt; &lt;ul&gt; &lt;li&gt; "class =" wendatitle "&gt; &lt;? Php echo $ dj [$ I] ['BP _ ptitle'];?&gt; &lt;/Li&gt; &lt;li&gt; post identity: &lt;? Php if ($ dj [$ I] ['BP _ Ptype '] = 0) echo "instructor "; if ($ dj [$ I] ['BP _ Ptype '] = 1) echo "student";?&gt; | Sender ID: &lt;? Php echo $ dj [$ I] ['BP _ puserid'];?&gt; &lt;/Li&gt; &lt;li&gt; Question Time: &lt;? Php echo $ dj [$ I] ['BP _ ptime'];?&gt; &lt;/Ul&gt; &lt;/p&gt; &lt;! -- Qaslider --&gt; &lt;/p&gt; &lt;! -- Wenda-list --&gt; &lt;? Php // end loop}?&gt; &lt;/P&gt; &lt;! -- Wrap --&gt; &lt;/p&gt; &lt;! -- Wrap_right --&gt; &lt;/p&gt; &lt;! -- Middle --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 2 width = "95%" align = center border = 0&gt; &lt;TR height = 20&gt; &lt;TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;/pre&gt; The HTML code ".. /database/httppost. php "medium ".. "indicates that the Directory of the code is returned to the top-level directory, as shown in. the source code is stored in the htdocs folder in Apache. &lt;Br/&gt; &lt;p class = "sycode"&gt; &lt;br/&gt; &lt;/p&gt; &lt;p class = "sycode"&gt; The main_right3-1-content.php code is as follows: &lt;br/&gt; &lt;pre name = "code" class = "sycode"&gt; &lt;? Phpheader ("Content-Type: text/html; charset = utf-8"); include ("../database/human. php"); session_start ();?&gt; &lt;Link rel = "stylesheet" href = "css/main.css" type = "text/css"/&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = "100%" align = center border = 0&gt; &lt;TR height = 28&gt; &lt;TD background = images/title_bg1.jpg&gt; Current location: BBS Forum &lt;/TD&gt; &lt;TD align = right&gt; back &lt;/TD&gt; &lt;/TR&gt; &lt;TD bgColor = # b1ceef height = 1 colspan = "2"&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 10&gt; &lt;TD background = images/shadow_bg.jpg colspan = "2"&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;! -- Get content in the PHP database --&gt; &lt;? Php // query BBS $ hgi = new HttpPostInf (); $ result = $ hgi-&gt; doquery ('2', "select * from BBS_Post where BP_Pid = '". $ _ GET ['bbsid ']. "';"); // parse json $ dj = json_decode ($ result, true); $ jcount = count ($ dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {$ _ SESSION ['bbsid '] = $ dj [$ I] ['BP _ Pid'];?&gt; &lt;P class = "middle"&gt; &lt;p class = "wrap"&gt; &lt;p class = "wrap_left"&gt; &lt;p class = "wenda-head"&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = "100%" align = center border = 0 bgcolor = "blue"&gt; &lt;TR height = 10&gt; &lt;TD&gt; &lt;/TR&gt; &lt;TR height = 22&gt; &lt;TD style = "PADDING-LEFT: 10px; FONT-WEIGHT: bold; COLOR: # ffffff "align = left&gt; [post] &lt;? Php echo $ dj [$ I] ['BP _ ptitle'];?&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;TR height = 10&gt; &lt;TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;/p&gt; &lt;! -- Main poster content --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = "95%" align = center border = 0&gt; &lt;tr&gt; &lt;td valign = "top"&gt; &lt;p align = "middle" width = 150&gt; &lt;BR/&gt; Owner 1 # &lt;BR/&gt; &lt;? Php echo $ dj [$ I] ['BP _ puserid'];?&gt; &lt;BR/&gt; identity &lt;? Php if ($ dj [$ I] ['BP _ Ptype '] = 0) echo "instructor "; if ($ dj [$ I] ['BP _ Ptype '] = 1) echo "student";?&gt; &lt;BR/&gt; &lt;? Php echo $ dj [$ I] ['BP _ ptime'];?&gt; &lt;/P&gt; &lt;/td&gt; &lt;! -- The multi-line text input control disabled = "disabled" cannot be edited --&gt; &lt;td&gt; &lt;textarea rows = "15" type = "text" width = "400px" style = "resize: none; font-size: 16px; "maxlength =" 2000 "name =" content "cols =" 60 "disabled =" disabled "&gt; &lt;? Php echo $ dj [$ I] ['BP _ cont'];?&gt; &lt;/Textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;TR height = 4&gt; &lt;TD colspan = "3"&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;tr&gt; &lt;td colspan = "2"&gt; <pr width = "100%" size = "2" color = "# FF0000"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/TABLE&gt; &lt;! -- The while loop in the above php is not over, and there are right brackets --&gt; &lt;? Php} // query BBS $ hgi = new HttpPostInf (); $ result = $ hgi-&gt; doquery ('2', "select * from BBS_Reply where BR_Pid = '". $ _ GET ['bbsid ']. "';"); // parse json $ dj = json_decode ($ result, true); $ jcount = count ($ dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {?&gt; &lt;! -- Floor reply content --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 0 width = "95%" align = center border = 0&gt; &lt;tr&gt; &lt;td valign = "top"&gt; &lt;p align = "middle" width = 150&gt; &lt;BR/&gt; floor &lt;? Php $ _ SESSION ['bbshfid'] = time (); echo $ I + 2;?&gt; # &lt;BR/&gt; &lt;? Php echo $ dj [$ I] ['Br _ ruserid'];?&gt; &lt;BR/&gt; identity &lt;? Php if ($ dj [$ I] ['Br _ Rtype '] = 0) echo "instructor "; if ($ dj [$ I] ['Br _ Rtype '] = 1) echo "student";?&gt; &lt;BR/&gt; &lt;? Php echo $ dj [$ I] ['Br _ ptime'];?&gt; &lt;BR/&gt; reply floor &lt;? Php echo $ dj [$ I] ['Br _ Pfloor '];?&gt; # &lt;/P&gt; &lt;/td&gt; &lt;! -- The multi-line text input control disabled = "disabled" cannot be edited --&gt; &lt;td&gt; &lt;textarea rows = "15" type = "text" width = "400px" style = "resize: none; font-size: 16px; "maxlength =" 2000 "name =" content "cols =" 60 "disabled =" disabled "&gt; &lt;? Php echo $ dj [$ I] ['Br _ cont'];?&gt; &lt;/Textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;TR height = 4&gt; &lt;TD colspan = "3"&gt; &lt;/TD&gt; &lt;/TR&gt; &lt;tr&gt; &lt;td colspan = "2"&gt; <pr width = "100%" size = "2" color = "# FF0000"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/TABLE&gt; &lt;? Php }?&gt; &lt;! -- Reply content --&gt; &lt;/p&gt; &lt;! -- Wrap --&gt; &lt;/p&gt; &lt;! -- Wrap_right --&gt; &lt;/p&gt; &lt;! -- Middle --&gt; &lt;TABLE cellSpacing = 0 cellPadding = 2 width = "95%" align = center border = 0&gt; &lt;TR height = 20&gt; &lt;TD&gt; &lt;/TR&gt; &lt;/TABLE&gt; &lt;! -- Submit the POST database form processing on the current page --&gt; &lt;? Phpif (! Empty ($ _ POST ['bbscontent']) {if ($ _ SESSION ['Radio '] = 1) $ a = 1; // student if ($ _ SESSION ['Radio '] = 2) $ a = 0; // instructor // SQL update $ SQL = "INSERT INTO BBS_Reply (BR_Rid, BR_Pid, BR_Ruserid, BR_Rtype, BR_Ptime, BR_Pfloor, BR_Cont) VALUES ("; $ SQL. = "'". $ _ SESSION ['bbshfid']. "',"; $ SQL. = "'". $ _ SESSION ['bbsid ']. "',"; $ SQL. = "'". $ _ SESSION ['Number']. "',"; $ SQL. = "'". $. "',"; $ SQL. = "'". date ('Y-m-D '). "',"; $ SQL. = "'". $ _ POST ['LC ']. "', "; $ SQL. = "'". $ _ POST ['bbscontent']. "'"; $ SQL. = ");"; // update information // echo $ SQL; $ hgi = new HttpPostInf (); $ result = $ hgi-&gt; doquery ('1 ', $ SQL); // echo "script" alert ('Congratulations, modification successful! '); Script "; header ('Location: main_right3-1.php');}?&gt; &lt;/Pre&gt; shows the display effect of post and reply messages: &lt;br/&gt; &lt;p class = "sycode"&gt; &lt;/p&gt; &lt;p class = "sycode"&gt; &lt;br/&gt; &lt;p class = "sycode"&gt; the post code is no longer posted, you can view the source code. You may be confused about the database access content! &lt;Br/&gt; &lt;/p&gt; 3. PHP defining classes and member functions in PHP, the websites we usually complete during course learning are based on the process-oriented method, thus ignoring its object-oriented knowledge, obviously, I also made such a mistake. &lt;Br/&gt; PS: because this project is an assignment of the object-oriented analysis and development course, it must be analyzed and implemented using object-oriented knowledge. Suddenly one day I found that PHP used to implement HTML and PHP layout background, without the knowledge of classes, encapsulation, and inheritance. However, after reading the relevant information, I found that PHP has these things. &lt;Br/&gt; Later, we defined different classes in the implementation of this project (thanks to PU Ge). here we only give an example of the database and Human classes. &lt;Br/&gt; &lt;pre name = "code" class = "sycode"&gt; &lt;? Phpheader ("Content-Type: text/html; charset = utf-8"); class HttpPostInf {function _ construct () {// no parameter constructor} function doquery ($ type, $ SQL) {// network communication function $ data = array ('sqltype' =&gt; $ type, 'sqlexe '=&gt; $ SQL); $ data = http_build_query ($ data ); $ opts = array ('http' =&gt; array ('method' =&gt; 'post', 'header' =&gt; "Content-type: application/x-www-form-urlencoded \ r \ n ". "Content-Length :". strlen ($ data ). "\ r \ n", 'content' =&gt; $ data); $ context = stream_context_create ($ opts); $ html = file_get_contents (' http://courseweb.sinaapp.com/courseweb.php ', False, $ context); return $ html ;}}?&gt; &lt;/Pre&gt; The Human class is defined at the same time, and Student and Teacher inherited from the class are login users with two identities. The constructor and instantiation are all written in the member functions. &lt;Br/&gt; &lt;pre name = "code" class = "sycode"&gt; &lt;? Phpheader ("Content-Type: text/html; charset = utf-8"); include_once ("httppost. php "); // Human, with the common attributes and methods of teachers and students class Human {private $ hid; // unique ID private $ pwd; // password private $ name; // name private $ sex; // gender private $ email; // email function _ construct () {// no parameter constructor} // static verification function static function id_vf ($ id, $ spwd, $ type) {// class static method type = 1 is a student, 2 is instructor $ hpi = new HttpPostInf (); if ($ type = 1) {$ result = $ hpi-&gt; doquery ('2', "select * from Student_In Fo where Sinf_id = '". $ id. "';"); if ($ result = 'error' | $ result = 'null') {// return-1; // no user, returns 0} else {$ dj = json_decode ($ result, true); $ jcount = count ($ dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {// only one password $ right_pwd = $ dj [$ I] ['sinf _ pwd']; // student logon password} if ($ spwd = $ right_pwd) return 1; // if the verification is successful, you can log on to else return 0; // incorrect password} else if ($ type = 2) {$ result = $ hpi-&gt; doquery ('2', "select * from Teacher_Info where TI_id = '". $ id. "';"); If ($ result = 'error' | $ result = 'null') {// return-1; // no user, returns 0} else {$ dj = json_decode ($ result, true); $ jcount = count ($ dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {// only one password $ right_pwd = $ dj [$ I] ['Ti _ pwd']; // student logon password} if ($ spwd = $ right_pwd) return 1; // if the verification is successful, you can log on to else return 0; // incorrect password }}} class Student extends Human {private $ bir; // date of birth private $ maj; // professional private $ eym; // year of admission private $ score; // score function _ _ Construct ($ sid) {// 1 parameter constructor $ this-&gt; hid = $ sid; $ stu = new HttpPostInf (); $ result = $ stu-&gt; doquery ('2', "select * from Student_Info where Sinf_ID = '". $ sid. "';"); // echo 'result :'. $ result; // parse json $ dj = json_decode ($ result, true); $ jcount = count ($ dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {// returns only one, so only one is allowed, jcount = 1 $ this-&gt; bir = $ dj [$ I] ['sinf _ bir']; $ this-&gt; maj = $ dj [$ I] ['sinf _ Maj']; $ this-&gt; eym = $ dj [$ I] ['sinf _ eym']; $ this-&gt; score = $ dj [$ I] ['si Nf_Score ']; // or write: $ score = $ dj-&gt; Sinf_Bir; $ this-&gt; pwd = $ dj [$ I] ['sinf _ pwd']; $ this-&gt; name = $ dj [$ I] ['sinf _ name']; $ this-&gt; sex = $ dj [$ I] ['sinf _ Sex ']; $ this-&gt; email = $ dj [$ I] ['sinf _ Email '] ;}} function getname () {return $ this-&gt; name;} function getsex () {return $ this-&gt; sex;} function getemail () {return $ this-&gt; email;} function getpwd () {return $ this-&gt; pwd;} function getbir () {return $ this-&gt; bir;} function getmaj () {return $ this-&gt; maj;} Function geteym () {return $ this-&gt; eym;} function getscore () {return $ this-&gt; score ;}} class Teacher extends Human {private $ ptitle; // Title private $ res; // result private $ award; // award function _ construct ($ tid) {// 1 parameter constructor $ this-&gt; hid = $ tid; $ stu = new HttpPostInf (); $ result = $ stu-&gt; doquery ('2 ', "select * from Teacher_Info where TI_ID = '". $ tid. "';"); // echo 'result :'. $ result; // parse json $ dj = json_decode ($ result, true); $ jcount = count ($ Dj); for ($ I = 0; $ I &lt;$ jcount; $ I ++) {// returns only one, so you can just take one, jcount = 1 $ this-&gt; ptitle = $ dj [$ I] ['Ti _ ptitle']; $ this-&gt; res = $ dj [$ I] ['Ti _ Res']; $ this-&gt; award = $ dj [$ I] ['Ti _ Award ']; // or write: $ score = $ dj-&gt; Sinf_Bir; $ this-&gt; pwd = $ dj [$ I] ['Ti _ pwd']; $ this-&gt; name = $ dj [$ I] ['Ti _ name']; $ this-&gt; sex = $ dj [$ I] ['Ti _ sex']; $ this-&gt; email = $ dj [$ I] ['Ti _ mail'] ;}} function getname () {return $ this-&gt; name;} function getsex () {return $ this-&gt; sex;} function getemail () {Return $ this-&gt; email;} function getpwd () {return $ this-&gt; pwd;} function getptitle () {return $ this-&gt; ptitle ;} function getres () {return $ this-&gt; res;} function getaward () {return $ this-&gt; award ;}}?&gt; &lt;/Pre&gt; call the classes HttpPostInf and Human defined above to implement simple database access code as follows: &lt;br/&gt; &lt;? Php &lt;br/&gt; // query Post &lt;br/&gt; $ hgi = new HttpPostInf (); &lt;br/&gt; $ result = $ hgi-&gt; doquery ('2 ', "select * from BBS_Post;"); // SQL statement &lt;br/&gt; // parse json &lt;br/&gt; $ dj = json_decode ($ result, true ); &lt;br/&gt; $ jcount = count ($ dj); &lt;br/&gt; for ($ I = 0; $ I &lt;$ jcount; $ I ++) {&lt;br/&gt; echo $ dj [$ I] ['BP _ Pid ']; &lt;br/&gt;}&lt; br/&gt;?&gt; &lt;Br/&gt; after a user logs on, the Session is used to record the user's id, and then all the information of the user can be obtained through class instantiation. The simple code is as follows: &lt;br/&gt; $ h1 = new Student ('123'); &lt;br/&gt; echo $ h1-&gt; getname (); echo '&lt;br&gt; '; &lt;br/&gt; echo $ h1-&gt; getsex (); echo '&lt;br&gt;'; &lt;br/&gt; echo $ h1-&gt; getemail (); echo '&lt;br&gt; '; &lt;br/&gt; at last, I hope the article will be helpful to everyone. in particular, I found few articles on PHP! A relatively large number of articles are about PHP details, and I hope you can learn about PHP. I always feel that I have some questions about blog writing, but I cannot say it myself. I hope you can raise some shortcomings! This code database is deployed on SAE, so running it directly can show the effects of all the above figures. &lt;Br/&gt; (By: Eastmount four o'clock P.M)

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.