注:eWebEditorPHP38编辑器文件夹的名称。
    id=content中content为上面隐藏域的名称

14、">
search
Homephp教程php手册PHP常用代码大全
PHP常用代码大全Jun 14, 2016 am 12:02 AM
phpcodeOpen sourceprogrammingprogramming languagesoftware development

 

1、连接MYSQL数据库代码
$connec=mysql_connect("localhost","root","root") or die("不能连接数据库服务器: ".mysql_error());
mysql_select_db("liuyanben",$connec) or die ("不能选择数据库: ".mysql_error());
mysql_query("set names 'gbk'");
?>

2、读取数据库,并实现循环输出
$sql="select * from liuyan order by ly_id desc";
$conn=mysql_query($sql,$connec);
while($rs=mysql_fetch_array($conn)){
?>
循环的内容.........
}
?>

3、如何实现分页,包括两个函数,两个调用
1)两个函数

//分页函数
function genpage(&$sql,$page_size=2)
{
      global $prepage,$nextpage,$pages,$sums; //out param
      $page = $_GET["page"];
      $eachpage = $page_size;
      $pagesql = strstr($sql," from ");
      $pagesql = "select count(*) as ids ".$pagesql;
      $conn = mysql_query($pagesql) or die(mysql_error());
      if($rs = mysql_fetch_array($conn)) $sums = $rs[0];
      $pages = ceil(($sums-0.5)/$eachpage)-1;
      $pages = $pages>=0?$pages:0;
      $prepage = ($page>0)?$page-1:0;
      $nextpage = ($page      $startpos = $page*$eachpage;
    $sql .=" limit $startpos,$eachpage ";
}
// 显示分页
function showpage()
{
    global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function
    $shownum =10/2;
    $startpage = ($page>=$shownum)?$page-$shownum:0;
    $endpage = ($page+$shownum 
    echo "共".($pages+1)."页: ";
    if($page>0)echo "首页";
    if($startpage>0)
        echo " ... ?";
    for($i=$startpage;$i    {
        if($i==$page)    echo " [".($i+1)."] ";
        else        echo " ".($i+1)." ";
    }
    if($endpage        echo "? ... ";
    if($page        echo "尾页";
}
//显示带分类的分页
function showpage1()
{
$fenlei=$_GET["fenleiid"];
    global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function
    $shownum =10/2;
    $startpage = ($page>=$shownum)?$page-$shownum:0;
    $endpage = ($page+$shownum 
    echo "共".($pages+1)."页: ";
    if($page>0)echo "首页";
    if($startpage>0)
        echo " ... ?";
    for($i=$startpage;$i    {
        if($i==$page)    echo " [".($i+1)."] ";
        else        echo " ".($i+1)." ";
    }
    if($endpage        echo "? ... ";
    if($page        echo "尾页& amp; gt;";
}
?>
2)两个调用
第一个
$sql="select * from liuyan order by ly_id desc";
genpage($sql); //只需要正常代码加上这一行就ok。
$conn=mysql_query($sql,$connec);
while($rs=mysql_fetch_array($conn)){
?>
第二个
}
?>
showpage(); //显示页
?>
mysql_close();  
?>

4、服务器端包含


5、如何将一条记录写入数据库,然后提示并跳转页面
$ly_title=$_POST["ly_title"];
$ly_content=$_POST["ly_content"];
$ly_time=$_POST["ly_time"];
$ly_author=$_POST["ly_author"];
$ly_email=$_POST["ly_email"];
$sql="insert into liuyan(ly_title,ly_content,ly_time,ly_author,ly_email) values('".$ly_title."','".$ly_content."','".$ly_time."','".$ly_author."','".$ly_email."')";
mysql_query($sql,$connec);
echo("");
?>

6、 弹出对话框,并发生页面跳转
echo("");
?>

7、 信息查看页面(有条件读取数据库)
1)有条件读取数据库
$sql="select * from liuyan where ly_id=$_GET[id]";
$conn=mysql_query($sql,$connec);
$rs=mysql_fetch_array($conn);
?>
2) 将某个字段输出
=$rs[ly_title]?>
3)关闭数据库
mysql_close(); 
?>

8、对数据库中某一条记录进行更新操作,并作提示跳转
$ly_title=$_POST["ly_title"];
$ly_content=$_POST["ly_content"];
$ly_time=$_POST["ly_time"];
$ly_author=$_POST["ly_author"];
$ly_email=$_POST["ly_email"];
$sql="update liuyan set ly_title='$ly_title',ly_content='$ly_content',ly_time='$ly_time',ly_author='$ly_author',ly_email='$ly_email' where ly_id=$_GET[id]";
mysql_query($sql,$connec);
echo("");
?>

9、 如何删除数据库中的一条记录
$sql="delete from liuyan where ly_id=$_GET[id]";
mysql_query($sql,$connec);
echo("");
?>

10、 如何进行会员登录验证
session_start();
$username=$_POST["username"];
$password=$_POST["password"];
$sql="select * from admin where username='".$username."' && password='".$password."'";
$result=mysql_query($sql,$connec);
if($row=mysql_fetch_array($result)){
session_register("admin");
$admin=$username;
echo("");}
else
{
echo("& gt;");
}
mysql_close();
?>

11、如何对SESSION进行检验(后台检查页面的制作)
session_start();
if(!isset($_SESSION["admin"])){
header("location:login.php");
exit;
}
?>

12、 验证用户名及密码是否填写(javascript)


13、 在PHP中调用编辑器的方法
1)将编辑器文件夹放置后台管理文件夹内。
2)利用以下语句进行引入操作。


注:eWebEditorPHP38编辑器文件夹的名称。
    id=content中content为上面隐藏域的名称

14、循环输出(能够实现分列)
   1)首先插入一行一列表格
$i=1;
?> 


  
    while($rs=mysql_fetch_array($conn)){
?>    
  
         if ($i % 2==0) {
   echo "";
   }
   $i++;
    }
   ?>
  

    被循环的其它表格和输出
  


15、 给下拉列表框绑定数据(并且在修改时默认选中)


16、获取字符长度函数
strlen($c)>12

17、 定义一个字符截取函数
用法:=substrgb($rs["title"],10)?>
function substrgb($in,$num){
   $pos=0;
   $out="";
   while($c=substr($in,$pos,1)){
    if($c=="\n") break;
    if(ord($c)>128){
     $out.=$c;
     $pos++;
     $c=substr($in,$pos,1);
 
   $out.=$c;
    }else{
     $out.=$c;
    }
    $pos++;
    if($pos>=$num) break;
   }
   if($out!=$in) $out = $out . "...";
   return $out;
}

18、判断是否是数字
!is_numeric(qq)

19、PHP技术中获取当前日期
$ptime=date("y-m-d");

20、用户注册时所使用的PHP验证程序
if ($admin=="" or (strlen($admin)>16) or (strlen($admin)     echo "";
}
if ($password=="" or strlen($password)>16 or strlen($password)     echo "";
}
if ($password=="") {
     echo "";
}else{
if ($password!=$password1) {
     echo "";
}
}
if ($wt="") {
     echo ""; 
}
if ($da="") {
     echo "";
   
}
if ($qq!="") {
if (!is_numeric($qq)) {
     echo "";
}
}
if ($youbian=="" or strlen($youbian)!=6) {
     echo "";
}
if ($youbian!="") {
if (!is_numeric($youbian)) {
     echo "";
}
}
if ($dizhi="") {
     echo "";
}
if ($mail=="") {
echo "";
}
if ($textarea=="") {
echo "";
}
if ($textarea=="" or strlen(textarea)>150) {
   echo "";
}

24、对输出的内容进行判断,从而输出其它结果
   if ($rs["active"]==1) {
   echo "激活";
   }else{
   echo "禁用";
   }
?>

25.字符截取函数
=substr("$rs[zixun_biaoti]",0,28)?>

26.男女问题或单选带选择的
>男
>女

27.单选不带单选框的

">锁定
else{?>
&action=no">解锁

它的 save页是

$hy_id=$_GET['id'];
$action=$_GET['action'];
if ($action=='yes'){
$sql="update hybiao set hy_zhuangtai='锁定' where hy_id='$id'";
$query=mysql_query($sql,$connec);
echo("");
}
else{
$sql="update hybiao set hy_zhuangtai='正常' where hy_id='$id'";
$query=mysql_query($sql,$connec);
echo("");
}
mysql_close();
?>

28. 如果文字过长,则将过长的部分变成省略号显示

就是比如有一行文字,很长,表格内一行显示不下.


29.
禁止复制,鼠标拖动选取

30.大 中 小 文字的变化

需要指定大小的文字
大 中 小

30.添加到收藏夹和设为首页
设为首页
收藏本站

31.记录并显示网页的最后修改时间


32.节日倒计时


33.打开窗口即最大化


34.加入背景音乐
只适用于IE
对Netscape ,IE 都适用

35.滚动

滚动信息


36.防止点击空链接时,页面往往重置到页首端
代码“javascript:void(null)”代替原来的“#”标记

37.不能点右键,不用CTRL+A,不能复制作!
onkeypress="window.event.returnValue=false"
onkeydown="window.event.returnValue=false"
onkeyup="window.event.returnValue=false"
ondragstart="window.event.returnValue=false"
onselectstart="event.returnValue=false">


37.随机变换背景图象(一个可以刷新心情的特效)


38.划过链接 手型鼠标
style="cursor:hand"

39.如何关闭层

关闭层

40.[关闭窗口]

41.凹陷文字背景为灰色


怎么样,我凹下去了吧?

你不想试试吗?

www.lenvo.cn



42.给表格做链接






43.后退&关闭窗口
后退:javascript:history.back(1)
关闭:javascript:window.close();

44.如果文字过长,则将过长的部分变成省略号显示

就是比如有一行文字,很长,表格内一行显示不下.


45.禁止复制,鼠标拖动选取

<script></script><script></script><script></script>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么设置implode没有分隔符php怎么设置implode没有分隔符Apr 18, 2022 pm 05:39 PM

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool