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<$pages)?$page+1:$pages; $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<=$pages)?$page+$shownum:$pages;
20、用户注册时所使用的PHP验证程序 if ($admin=="" or (strlen($admin)>16) or (strlen($admin)<2)) { echo ""; } if ($password=="" or strlen($password)>16 or strlen($password)<6) { 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 ""; }
$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(); ?>