Home  >  Article  >  php教程  >  php实战第十六天

php实战第十六天

WBOY
WBOYOriginal
2016-06-13 10:57:31726browse

下面图片是今天做的前台和后台,前台是套用上星期五的模板.后台是随手写的.

 

今天学习到了

css的 overflow设置内容超过范围就可以给滚动条或者隐藏滚动条

overflow:hidden 就是隐藏咯

php方面又写了一次mysql类.超级简单的


[php]
    /**
    * 用于mysql操作的类
    */ 
    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); 
 
        } 
 
 
    } 
 ?> 

 /**
 * 用于mysql操作的类
 */
 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);

  }


 }
 ?>

今天遇到纠结的问题,交互动作..本身是想写mvc的单一入口形式,但是这样写代码速度不就慢了,然后我就采取了一直似乎不错的解决方案

1.建立action文件夹,建立 type.php 用于文章栏目操作

2.建立 article.php 用于文章操作,

这样的话 我用ajax发送请求只需"/action/type.php?action=list"搞定.然后做判断什么的执行对应代码.用了 switch语句.


[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;
 }


?>

 

Statement:
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
Previous article:php实战第二十天Next article:php缩放图片