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);
}
}
?>
/**
*/
class db_mysql
{
var $conn;
function __construct($localhost,$userName,$password,$dbName)
{
mysql_select_db($dbName,$this->conn);
Mysql_query("set names utf8",$this->conn);
}
{
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
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;
}
?>