array(2) { ["docs"]=> array(10) { [0]=> array(10) { ["id"]=> string(3) "428" ["text"]=> string(77) "Visual Studio 2017 单独启动MSDN帮助(Microsoft Help Viewer)的方法" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(8) "DonetRen" ["tagsname"]=> string(55) "Visual Studio 2017|MSDN帮助|C#程序|.NET|Help Viewer" ["tagsid"]=> string(23) "[401,402,403,"300",404]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400964" ["_id"]=> string(3) "428" } [1]=> array(10) { ["id"]=> string(3) "427" ["text"]=> string(42) "npm -v;报错 cannot find module "wrapp"" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "zzty" ["tagsname"]=> string(50) "node.js|npm|cannot find module "wrapp“|node" ["tagsid"]=> string(19) "[398,"239",399,400]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400760" ["_id"]=> string(3) "427" } [2]=> array(10) { ["id"]=> string(3) "426" ["text"]=> string(54) "说说css中pt、px、em、rem都扮演了什么角色" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(12) "zhengqiaoyin" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511400640" ["_id"]=> string(3) "426" } [3]=> array(10) { ["id"]=> string(3) "425" ["text"]=> string(83) "深入学习JS执行--创建执行上下文(变量对象,作用域链,this)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "Ry-yuan" ["tagsname"]=> string(33) "Javascript|Javascript执行过程" ["tagsid"]=> string(13) "["169","191"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511399901" ["_id"]=> string(3) "425" } [4]=> array(10) { ["id"]=> string(3) "424" ["text"]=> string(30) "C# 排序技术研究与对比" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "vveiliang" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(8) ".Net Dev" ["catesid"]=> string(5) "[199]" ["createtime"]=> string(10) "1511399150" ["_id"]=> string(3) "424" } [5]=> array(10) { ["id"]=> string(3) "423" ["text"]=> string(72) "【算法】小白的算法笔记:快速排序算法的编码和优化" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(9) "penghuwan" ["tagsname"]=> string(6) "算法" ["tagsid"]=> string(7) "["344"]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511398109" ["_id"]=> string(3) "423" } [6]=> array(10) { ["id"]=> string(3) "422" ["text"]=> string(64) "JavaScript数据可视化编程学习(二)Flotr2,雷达图" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "chengxs" ["tagsname"]=> string(28) "数据可视化|前端学习" ["tagsid"]=> string(9) "[396,397]" ["catesname"]=> string(18) "前端基本知识" ["catesid"]=> string(5) "[198]" ["createtime"]=> string(10) "1511397800" ["_id"]=> string(3) "422" } [7]=> array(10) { ["id"]=> string(3) "421" ["text"]=> string(36) "C#表达式目录树(Expression)" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(4) "wwym" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(4) ".NET" ["catesid"]=> string(7) "["119"]" ["createtime"]=> string(10) "1511397474" ["_id"]=> string(3) "421" } [8]=> array(10) { ["id"]=> string(3) "420" ["text"]=> string(47) "数据结构 队列_队列实例:事件处理" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(7) "idreamo" ["tagsname"]=> string(40) "C语言|数据结构|队列|事件处理" ["tagsid"]=> string(23) "["246","247","248",395]" ["catesname"]=> string(12) "数据结构" ["catesid"]=> string(7) "["133"]" ["createtime"]=> string(10) "1511397279" ["_id"]=> string(3) "420" } [9]=> array(10) { ["id"]=> string(3) "419" ["text"]=> string(47) "久等了,博客园官方Android客户端发布" ["intro"]=> string(288) "目录 ECharts 异步加载 ECharts 数据可视化在过去几年中取得了巨大进展。开发人员对可视化产品的期望不再是简单的图表创建工具,而是在交互、性能、数据处理等方面有更高的要求。 chart.setOption({ color: [ " ["username"]=> string(3) "cmt" ["tagsname"]=> string(0) "" ["tagsid"]=> string(2) "[]" ["catesname"]=> string(0) "" ["catesid"]=> string(2) "[]" ["createtime"]=> string(10) "1511396549" ["_id"]=> string(3) "419" } } ["count"]=> int(200) } 222 数据库连接:操作数据增删改查 - 爱码网

1.

查询:

数据的显示,这里就可以嵌入php来进行数据的输出

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
</head>

<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>代号</td>
        <td>名称</td>
        <td>性别</td>
        <td>生日</td>
        <td>班级</td>
        <td>操作</td>
    </tr>
<?php
$db = new MySQLi("localhost","root","12345678","heiheihei");
//连接数据库
$sql = "select * from student ";
//写sql语句
$r = $db->query($sql);
//执行sql语句返回给r
if($r)//条件
{
    while ($attr = $r->fetch_row())
    {
        $ssex = "";
         if($attr[2])
         {
             $ssex = "男";
         }
         else
             {
                 $ssex = "女";
             }
        echo
        "
 <tr>
        <td>{$attr[0]}</td>
        <td>{$attr[1]}</td>
        <td>{$ssex}</td>
        <td>{$attr[3]}</td>
        <td>{$attr[4]}</td>
//添加一个单击事件,防止不小心删掉
<td><a onclick=\"return confirm('确定要删除吗???')" 
href='shanchu.php?sno={$attr[0]}'>删除</a>
 <a href='xiugai.php?sno={$attr[0]}'>修改</a> </td> </tr>"; } } ?>

 

 

</table>
<a href="tianjia.php">添加页面</a>
</body>

</html>

 

2.

删除的处理页面

删除时是链接到删除处理页面的,所以还要写一个删除处理页面:

<?php
$aaa = $_GET ["sno"];  //删除方式使用的get,照旧
$db = new mysqli("localhost","root","12345678","heiheihei");
//连接...
$sql = "delete from student WHERE sno='{$aaa}'";
//写sql语句,sno主键
if($db->query($sql))  //执行sql语句
{
    header("location:text.php");
//删完回去表页面
}
else{
    echo "删除失败";
}
?>

 

来张效果图:

数据库连接:操作数据增删改查

3.

添加数据:

点击数据库连接:操作数据增删改查即可进入添加页面

添加页面:

<body>

<h1>添加</h1>
<form action="add.php" method="post" >
    <div>代号:<input type="text" name="sno"/></div>
    <div>名字:<input type="text" name="sname"/></div>
    <div>性别: <input type="radio" value="1" name="sex" /><input type="radio" value="0" name="sex"/></div>
    <div>日期:<input type="text" name="sbirthday"/></div>
//创建表时性别是用的1或2来表示的,要是进行修改不知道1或2代表了什么,所以就要进行处理,处理成用户能够明白的男和女
<div>班级: <select name="class">
   <?php
        $db= new MYSQLi("localhost","root","12345678","heiheihei");
//连接...
        $sql = " select * from class ";
//写sql...        

       $r = $db->query($sql);
//执行...返回...
        while($arr = $r->fetch_row())
        {
            echo "<option value='{$arr[0]}'>{$arr[1]}</option>";
            //添上以后回表页面
        }
        ?>

 

    </select>
    </div>
    <div><input type="submit" value="添加"/></div>
</form>

</body>

添加也需要一个处理页面来判断添加:

<?php
$sno = $_POST["sno"];
//$_POST 变量用于收集来自 method="post" 的表单中的值。
$sname = $_POST["sname"];
$ssex = $_POST["ssex"];
$sbirthday = $_POST["sbirthday"];
$class = $_POST["class"];
$db = new mysqli("localhost","root","12345678","heiheihei");
$sql = "insert into student VALUES ('{$sno}','{$sname}','{$ssex}','{$sbirthday}','{$class}')";
//向数据库中添加写的数据
   if($db->query($sql))
{
   header("location:text.php");
   //header() 函数向客户端发送原始的 HTTP 报头。
}
else {
    echo "添加失败";
}


?>

 

效果图:

数据库连接:操作数据增删改查

4.

修改数据:主键不可修改!!

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
</head>

<body>

<h1>修改</h1>
<?php
$sno = $_GET{"sno"};
$db = new mysqli("localhost","root","12345678","heiheihei");
$sql = "select * from student WHERE sno='{$sno}'";
$r = $db->query($sql);
$arr = $r->fetch_row();
?>

 

<form action="update.php" method="post">
    <div>代号:<input readonly="readonly" type="text" name="sno" value="<?php
echo $arr[0];
?>"/></div>
//readonly只可读
 <div>名称:<input type="text" name="sname" value="<?php echo $arr[1]; ?>"/></div> <div>性别: <input type="radio" name="ssex" value="1" <?php echo $arr[2]?"checked='checked'":""; ?>/>男 <!-- 三元运算符,如果性别=ture,默认值就在男上面,否则空--> <input type="radio" name="ssex" value="0" <?php echo $arr[2]?"":"checked='checked'"; ?>/>女 </div> <div>日期:<input type="text" name="sbirthday" value="<?php echo $arr[3]; ?>"/></div> <div>班级:<select name="class">
//value取默认值

 

 <?php
            $sclass = "select * from class";
            $rclass = $db->query($sclass);
            while($attr = $rclass->fetch_row())
            //取到的班级信息
            {
                //判断将要输出的班级是不是和该人员的是否相同
               if($arr[4]==$attr[0])//arr是班级名,attr是班级的代号,俩表
               {
                   echo "<option  value = '{$attr[0]}' selected='selected'>{$attr[1]}</option>";

               }
               else{
                   echo "<option  value = '{$attr[0]}'>{$attr[1]}</option>";
               }

            }
            ?>

 

        </select></div>
    <div><input type="submit" value="修改完毕"/></div>

</form>


</body>
</html>

 修改的处理页面:

<?php
$sno = $_POST["sno"];
$sname = $_POST["sname"];
$ssex = $_POST["ssex"];
$sbirthday = $_POST["sbirthday"];
$class = $_POST["class"];
$db = new mysqli("localhost","root","12345678","heiheihei");
$sql = "update student set sname='{$sname}',
ssex='{$ssex}',
sbirthday='{$sbirthday}',
class='{$class}' WHERE sno='{$sno}'";
//看一下是不是传递过来的sno值;
if($db->query($sql))
{
    header("location:text.php");
}
else{
    echo "修改失败";
}



?>

修改的效果图:

数据库连接:操作数据增删改查

 

相关文章: