溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

php程序設(shè)計(jì)經(jīng)典300例,第26-30例

發(fā)布時間:2020-07-15 08:48:37 來源:網(wǎng)絡(luò) 閱讀:443 作者:鐘澤鋒 欄目:web開發(fā)

第26例


會員信息分頁顯示
conn.php頁面:

<?php
header("Content-Type:text/html;charset=utf-8");
mysql_connect("localhost","root","") or die("數(shù)據(jù)庫連接有誤!");
mysql_select_db("student") or die("數(shù)據(jù)庫選擇有誤!");
mysql_query("set names 'utf8'");

?>

<?php
//user.php頁面:
$page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=5;    //顯示條數(shù)
$sql="select count(*) from student";
$result=mysql_query($sql);
$maxrows=mysql_result($result,0,0);
$maxpage=ceil($maxrows/$pagesize);
  if($page>$maxpage)
    {
        $page=$maxpage;
    }
    if($page<1)
     {
        $page=1;
     }
     $offset=($page-1)*$pagesize;
     $sql="select * from student limit{$offset},$pagesize";
     $result=mysql_query($sql);
      while($rows=mysql_fetch_assoc($result))
        {
            echo "<tr>";
            echo "<td>{$rows['id']}</td>";
            echo "<td>{$rows['username']}</td>";
            echo "<td>{$rows['email']}</td>";
            echo "<td>".date("Y-m-d H:i:s",$rows['datetime']+8*3600)."</td>";
            echo "</tr>";
        }
?>

第27例:

檢測用戶輸入日期的合法性

<form action="index.php" method="poost">
   <b>檢測用戶輸入日期的合法性</b>
   用戶名:<input type="text" name="username" value=""/><br />
   生日日期:<input type="text" name="userdate" value=""  size="18"/><br />
   <input type="submit" value="檢測"/>
   <input type="reset" value="重置"/>
</form>


<?php
   if(!empty($_POST['username']))
     {
        $arr=explode("-",$_POST['userdate']);
        if(checkdate($arr[1],$arr[2],$arr[0]))
          {
            echo "<script>alert('日期".$_POST['userdate']."格式正確')</script>";
          }else{
            echo "<script>alert('日期".$_POST['userdate']."格式不對')</script>";
          }
     }
?>


第28例
延遲php腳本的執(zhí)行時間

<?php

header("Content-Type:text/html;charset=utf-8");
echo "腳本載入時間:".date('Y-m-d H:i:s');
sleep(5); //腳本等待5秒后執(zhí)行
echo "<br/><br/>";
echo "執(zhí)行完畢時間:".date('Y-m-d H:i:s');
?>


第29例

使用php動態(tài)創(chuàng)建嵌套文件夾

<?php
header("Content-Type:text/html;charset=utf-8");
function createfolder($path)
   {
    if(!file_exists($path))
      {
        createfolder(dirname($path));
        mkdir($path,0777);
      }
   }
   createfolder("aa/bb/cc");//模擬測試
?>


第30例
用戶成績查詢


<?php

header("Content-Type:text/html;charset=utf-8");
?>
<form action="index.php" method="post" >
  <b>輸入分?jǐn)?shù)</b><br />
  分?jǐn)?shù):<input type="text" name="result" value=""/><br />
  <input type="submit" value="查詢"/>
  <input type="reset"/>
  
</form>



<?php

    if(!empty($_POST['result']))
       {
        $result=$_POST['result'];
        if($result>=80&&$result<=100)
          {
            echo "<script>alert('您的成績?yōu)閮?yōu)秀')</script>";
          }else if($result>=60&&$result<80)
             {
                echo "<script>alert('您的成績?yōu)楹细?)</script>";
             }else
                {
                    echo "<script>alert('您的成績?yōu)椴缓细?)</script>";
                }
       }
       
?>

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI