登录 主页面 删除 让缩略信息显示完整 (补:增加 修改 )

1.login.php   

<?php 
 include("init.inc.php");
 
$smarty->display("login.html");
 ?>

2.login.html  显示模板  在templates模板文件夹中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <h1>登录页面</h1>
    <form action="chuli.php" method="post">
        <div>用户名:<input type="text" name="uid"></div>
        <div>密&nbsp;&nbsp;&nbsp;&nbsp;码:<input type="text" name="pwd"></div>
        <div><input type="submit" value="登录"></div>
    </form>
</body>
</html>

3.chuli.php

<?php 
session_start();
$uid=$_POST["uid"];
$pwd=$_POST["pwd"];
include("DBDA.php");
$db=new DBDA();

$sql="select count(*) from users where username='{$uid}' and password='{$pwd}'";

$result=$db->StrQuery($sql,1,"mydb2");
if ($result==1) {
    $_SESSION["uid"]=$uid;
    header("location:main.php");
}

else{
    header("location:login.php");
}

 ?>

4.main.php

<?php 
session_start();


include("init.inc.php");
include("DBDA.php");

$db=new DBDA();



if (!empty($_SESSION["uid"])) {
    ;
    $sqlf="select * from news";
    $attr=$db->Query($sqlf,1,"mydb");

    $smarty->assign("news",$attr);

    $smarty->assign("jsurl","./js/jquery-1.11.2.min.js");
    $smarty->display("main.html");
}

else{
    header("location:login.php");
}
 ?>

5.main.html  显示模板  在templates模板文件夹中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="<{$jsurl}>"></script>
    <style type="text/css">
    .fu
    {
        width:360px;
        
        background-color: yellow;
        position: absolute;
    }

    </style>
</head>
<body>
    <h1>主页面</h1>
    <table style="position:absolute" width="100%" border="1" cellpadding="0" cellspacing="0">
        <tr>
            <td>编号</td>
            <td>标题</td>
            <td>内容</td>
            <td>时间</td>
            <td>类型</td>
            <td>操作</td>    
        </tr>
        <{foreach $news as $guo}>

        <tr>

            <td><{$guo[0]}></td>
            <td class='dq' bs='<{$guo[1]}>'><{$guo[1]|truncate:20}></td>
            <td><{$guo[2]|truncate:40}></td>
            <td><{$guo[3]}></td>
            <td><{$guo[4]}></td>
            <td><a href="shanchu.php?code=<{$guo[0]}>">删除</a></td> 
        </tr>
        <{/foreach}>
    </table>
</body>
<script type="text/javascript">
$(document).ready(function(e){
    
    $(".dq").mouseover(function(e){
        var top=e.clientY;  //获取鼠标位置
        var name=$(this).attr("bs");
        var div="<div class='fu' style='top:"+top+"px;left:100px'>"+name+"</div>";
        $(".fu").remove();
        $("body").append(div);
    })
    $(".dq").mouseleave(function(e){
        $(".fu").remove();
    })
});
    
</script>
</html>

6.shanchu.php  

<?php 
$code=$_GET["code"];
include("DBDA.php");
$db=new DBDA();

$sqls="delete from news where ids='{$code}'";

$db->Query($sqls,0,"mydb");

header("location:main.php");

 ?>

7.init.inc.php   (smarty.class.php 核心的配置文件/在libs文件夹下)需要应用smarty模板的php  页面引入

<?php

define("ROOT",str_replace("\\","/",dirname(__FILE__)).'/'); //常量ROOT中指定项目根目录

//echo str_replace("\\","/",dirname(__FILE__))."/";

require ROOT.'libs/Smarty.class.php'; //加载Smarty类文件

$smarty = new Smarty(); //实例化Smarty对象<br>


//$smarty -> auto_literal = false; //就可以让定界符号使用空格
$smarty->setTemplateDir(ROOT.'templates/'); //设置所有模板文件存放位置
//$smarty->addTemplateDir(ROOT.'templates2/'); //添加一个模板文件夹
$smarty->setCompileDir(ROOT.'templates_c/'); //设置编译过的模板存放的目录

$smarty->addPluginsDir(ROOT.'plugins/'); //设置为模板扩充插件存放目录
$smarty->setCacheDir(ROOT.'cache/'); //设置缓存文件存放目录
$smarty->setConfigDir(ROOT.'configs/'); //设置模板配置文件存放目录

$smarty->caching = false; //设置Smarty缓存开关功能
$smarty->cache_lifetime = 60*60*24; //设置缓存模板有效时间一天
$smarty->left_delimiter = '<{'; //设置模板语言中的左结束符
$smarty->right_delimiter = '}>'; //设置模板语言中的右结束符





?>

经过 login.html  chuli.php  到达  main.php    通过main.html  模板显示出来

 

 

位于编号为1 的新闻   被   点击右侧  删除掉

main.html页面   传值

<td><a href="shanchu.php?code=<{$guo[0]}>">删除</a></td> 

通过  shanchu.php  页面链接数据库  做删除动作

让缩略信息显示完整   通过js完成

 

<script type="text/javascript">
$(document).ready(function(e){
    
    $(".dq").mouseover(function(e){
        var top=e.clientY;  //获取鼠标位置
        var name=$(this).attr("bs");
        var div="<div class='fu' style='top:"+top+"px;left:100px'>"+name+"</div>";
        $(".fu").remove();
        $("body").append(div);
    })
    $(".dq").mouseleave(function(e){
        $(".fu").remove();
    })
});
    
</script>

posted @ 2016-05-24 15:20  梦里梦到梦  阅读(221)  评论(0编辑  收藏  举报