Home > Backend Development > PHP Tutorial > The sixteenth day of PHP practice_PHP tutorial

The sixteenth day of PHP practice_PHP tutorial

WBOY
Release: 2016-07-14 10:11:14
Original
907 people have browsed it

The pictures below are the front-end and back-end I made today. The front-end is based on the template from last Friday. The back-end is written casually.

I learned something today

The overflow setting of css can add scroll bars or hide scroll bars when the content exceeds the range

overflow:hidden means hiding

Written mysql class again in PHP. Super simple


[php]
/**
* Class for mysql operations
​*/
class db_mysql
{
        var $conn; 

Function __construct($localhost,$userName,$password,$dbName)
                                                                                    $this->conn=mysql_connect($localhost,$userName,$password);

mysql_select_db($dbName,$this->conn);
mysql_query("set names utf8",$this->conn);

         } 

Function __destruct()
                                                                  mysql_close($this->conn);
         } 


Function query($sql)
                                                                    //echo $sql;
                 return mysql_query($sql,$this->conn);

         } 


}  
?>

/**

* Classes used for mysql operations

​*/
class db_mysql
{
var $conn;

function __construct($localhost,$userName,$password,$dbName)
{

$this->conn=mysql_connect($localhost,$userName,$password);


mysql_select_db($dbName,$this->conn);
Mysql_query("set names utf8",$this->conn);

}

function __destruct()

{

Mysql_close($this->conn);

}


function query($sql)

{

//echo $sql;
Return mysql_query($sql,$this->conn);

}

}

?>


I encountered a tangled problem today, interactive actions... I wanted to write a single entry form of mvc, but writing code this way would be slow, so I adopted a solution that always seemed good

1. Create an action folder and create type.php for article column operations

2. Create article.php for article operations,

In this case, I only need to "/action/type.php?action=list" to send a request using ajax. Then I will determine what to execute and the corresponding code. I use a switch statement.


[php]
?php    
    require '../inc.php'; 
 
    switch ($_GET['action']) { 
 
        case 'submit': 
            if(!empty($_POST['typeName'])){ 
             
                $json['state']="no"; 
 
                $bool=$db->query("insert into typename (`name`) value('{$_POST['typeName']}')"); 
                if($bool){ 
                    $json['state']="ok"; 
                }else{ 
                    $json['error']='栏目插入失败'; 
                } 
                echo json_encode($json); 
            } 
 
            break; 
        case 'list': 
                $result = $db->query('select * from typename'); 
                $arr=array(); 
                while($row = mysql_fetch_assoc($result)){ 
                    $arr[]=$row; 
                } 
                echo json_encode($arr); 
            break; 
 
        default: 
            # code... 
            break; 
    } 
 
 
?> 

 require '../inc.php';

 switch ($_GET['action']) {

  case 'submit':
   if(!empty($_POST['typeName'])){
   
    $json['state']="no";

    $bool=$db->query("insert into typename (`name`) value('{$_POST['typeName']}')");
    if($bool){
     $json['state']="ok";
    }else{
     $json['error']='栏目插入失败';
    }
    echo json_encode($json);
   }

   break;
  case 'list':
    $result = $db->query('select * from typename');
    $arr=array();
    while($row = mysql_fetch_assoc($result)){
     $arr[]=$row;
    }
    echo json_encode($arr);
   break;

  default:
   # code...
   break;
 }


?>

 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477348.htmlTechArticleThe pictures below are the front-end and back-end I made today. The front-end is based on the template from last Friday. The back-end is written by hand. Today I learned about the overflow setting of css. When the content exceeds the range, you can give the scroll bar...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template