1、连接MYSQL数据库代码
APP的优势在于可实现随身随时预订,更符合用户当即决策的思路。途牛旅行网新近数据显示,用户通过手机客户端浏览景点、周边路线等指示,进而直接预订旅游产品.
<?php
$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、读取数据库,并实现循环输出
<?php
$sql="select*from liuyan order by ly_id desc";
$conn=mysql_query($sql,$connec);
while($rs=mysql_fetch_array($conn)){
?>
循环的内容.........
<?php
}
?>
3、如何实现分页,包括两个函数,两个调用
1)两个函数
<?
代码
/**************
*length-length of random string(must be a multiple of 2)
**************/
function readable_random_string($length=6){
$conso=array("b","c","d","f","g","h","j","k","l",
"m","n","p","r","s","t","v","w","x","y","z");
$vocal=array("a","e","i","o","u");
$password="";
((double)()*1000000);
$max=$length/2;
for($i=1;$i<=$max;$i++)
{
$password.=$conso[(0,19)];
$password.=$vocal[(0,4)];
}
return$password;
}
PHP生成一个随机字符串
如果不需要可阅读的字符串,使用此函数替代,即可创建一个随机字符串,作为用户的随机密码等。
代码
/*************
*l-length of random string
*/
function generate_rand($l){
$c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
((double)()*1000000);
for($i=0;$i<$l;$i++){
$rand.=$c[()%($c)];
}
return$rand;
}
3.PHP编码电子邮件地址
使用此代码,可以将任何电子邮件地址编码为html字符实体,以防止被垃圾邮件程序收集。
代码
function encode_email($email='info domain.com',$linkText='Contact Us',$attrs='class="emailencoder"')
{
//remplazar aroba y puntos
$email=('','@',$email);
$email=('.','.',$email);
$email=($email,5);
$linkText=('','@',$linkText);
$linkText=('.','.',$linkText);
$linkText=($linkText,5);
$part1='<a href="ma';
$part2='ilto:';
$part3='"'.$attrs.'>';
$part4='</a>';
$encoded='<script type="text/javascript">';
$encoded.="document.write('$part1');";
$encoded.="document.write('$part2');";
foreach($email as$e)
{
$encoded.="document.write('$e');";
}
$encoded.="document.write('$part3');";
foreach($linkText as$l)
{
$encoded.="document.write('$l');";
}
$encoded.="document.write('$part4');";
$encoded.='</script>';
return$encoded;
}