左边导航右边内容切换 php,jquery ajax实现点击左侧菜单栏,右侧对应div处加载相关页面并显示...

本文介绍了如何使用PHP进行数据发布,包括ym.php中的数据插入与查询操作,并利用Ajax实现实时更新显示。通过实例展示了如何通过Ajax从数据库获取数据并动态填充到页面中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ym.php:

数据发布

#box{width:900px;margin:20px auto 0px;padding-left:25px;

background:orange;border-radius: 10px;}

.text{width:870px;height:100px;margin-top: -20px;font:bold 25px/1em '黑体';resize: none;}

input{width:100px;height:30px;font:bold 20px/1em '黑体';}

ul{margin-top:3px;}

ul li{color:red;width:830px;border-bottom: 1px dashed blue;font:bold 18px/1.5em '黑体';}

a{width:60px;float:right;color:red;background:#ccc;

text-align:center;text-decoration:none;font:bold 20px/1em '黑体';}

a:hover{background:black;}

.a1{color:red;background:#ccc;float:right;margin-right:10px;}

header("Content-Type:text/html;charset=UTF-8");

include 'db.php';

$db = new DB();

if(isset($_POST['submit'])){

$a = $_POST['content'];

$date = date('Y-m-d H:i:s');

$sql = "insert into hh value(null,'$a','$date')";

$db->insert($sql);

// if(){

// //echo "";

// }

// if(empty($sql['content'])){

// echo "";

// }

}

?>

请输入发布数据内容

$sql = "select * from hh";

$res= $db->get($sql);

// $data=json_encode($res);

// echo $data;

for($i=1; $i <= count($res); $i++) {

$id = $res[$i-1][0];

$str = $res[$i-1][1];

echo "

发布数据$i: $str

删除

";

}

if (@$_GET['str']=='del') {

$id=$_GET['id'];

include_once('db.php');

$sql="delete from hh where id=$id";

$res=$db->delete($sql);

}

?>

ajax.html

查看数据内容

#box{position:relative;width:700px;font:bold 20px/1.5em '黑体';margin:20px auto 0px;

background:orange;padding-left:30px;color:red;margin-top:-5px;border-radius: 10px;}

#div1{width:720px;height:50px;background:pink;margin:5px auto 0px;

text-align: center;font:bold 30px/1.5em '黑体';border-radius: 10px;}

#btn1{position:absolute;width:130px;height:50px;margin-left:180px;

margin-top: 140px;font:bold 20px/1.5em '黑体';}

$(function(){

$('#btn1').bind('click', function(){

$.ajax({

url:"data.php",

type:"get",

success:function(data){

$("#box").html(data);

}});

});

})

Ajax 读 取 数 据 库 内 容 显 示 在 下 面
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值