PHP Combat 16th Day _php Tutorial

Source: Internet
Author: User
The picture below is today's front desk and backstage, the front desk is applied to the template on the Friday. Backstage is handy to write.

I learned it today.

CSS overflow settings can be used to scroll bars or hide scroll bars if the content is over range

Overflow:hidden is hidden.

PHP has written another MySQL class. Super simple


[PHP]
/**
* Classes 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 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);

}


}
?>

Today we encounter tangled problems, interactive actions. It's a single entry form for MVC, but it's not going to be slow, and then I've taken a seemingly good solution.

1. Create the Action folder, set up type.php for the article column operation

2. Establish article.php for the article operation,

In this case, I use Ajax to send a request just "/action/type.php?action=list". Then do the code to determine what to execute. A switch statement is used.


[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 ']= ' column insertion failed ';
}
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 ']= ' column insertion failed ';
}
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
}


?>

http://www.bkjia.com/PHPjc/477348.html www.bkjia.com true http://www.bkjia.com/PHPjc/477348.html techarticle The following picture is the front desk and backstage, the foreground is to apply the template on the Friday. Backstage is handy to write. Today, I learned that CSS overflow set content beyond the range can be used to scroll bar ...

  • 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.