PHP7常见sql、js语句

查询单条

$sql = 'select * from table';
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_assoc($result);

查询多条

$sql = 'select * from table';
$result = mysqli_query($conn,$sql);
foreach ($result as $value){
    echo $value['id'];
}

查询记录数

$sql = 'select count(*) as num from table';
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_assoc($result);
echo $row['num']; //条数

更新语句

$sql = 'update table set XX = 1 where id = 1';
if(!mysqli_query($conn, $sql)){
	echo '更新资料失败!';
	exit;
}

插入语句

$sql = 'insert into table (uid,XXX) value ("1","2")';
if(!mysqli_query($conn, $sql)){
	echo '新增资料失败!';
	exit;
}

删除语句

$sql = 'delete from table where id = 1';
if(!mysqli_query($conn,$sql)){
    echo '删除成功';
    exit;
}

 

 

 

js跳转页面

延时跳转
window.setTimeout('window.location="url"',1500);

当前页面跳转
window.location.href="http://www.baidu.com"

新窗口跳转
window.open("http://www.baidu.com")

返回上一页
window.history.back(-1);

 

jq定时执行

var re = '';
function fun(){
  console.log('here');
}
$(document).ready(function(){
  re = setInterval(fun,2000);
});

//停止执行
clearInterval(re);

 

你可能感兴趣的:(网站制作,jquery,mysqli)