完整代码如下:
<?php
//email验证
function validateEmail($email)
{
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}
//url验证
function validateURL(/blog_article/$url/index.html)
{
return eregi("^((ht|f)tp://)((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:\?\.-]*)*)$", $url);
}
//url转换
function convertURLS($text)
{
$text = eregi_replace("((ht|f)tp://www\.|www\.)([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})((/|\?)[a-z0-9~#%&\\/'_\+=:\?\.-]*)*)", "http://www.\\3", $text);
$text = eregi_replace("((ht|f)tp://)((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:\?\.-]*)*)", "<a href=/index.html"\\0\">\\0</a>", $text);
return $text;
}
//email转换
function convertMail($text)
{
$text = eregi_replace("([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))", "<a href='mailto:\\0'>\\0</a>", $text);
return $text;
}
function convertAllLinks($text)
{
$text = convertURLS($text);
$text = convertMail($text);
return $text;
}
?>
1、查询语句:
$conn=mysql_connect()("localhost","root","");
$db=mysql_select_db("lingyun");
$query="select * from message where tradetype='".$tradetype."'"; //交易类型,如出租,出售
$SQL=$SQL . "wuye='" . $wuye . "'";
if($housetype!="不限"){
$query.=" && housetype='".$housetype."'"; //房屋类型,如二室一厅,三室二厅
}
if($degree!="不限"){
$query.=" && degree='".$degree."'"; //新旧程度
}
if($wuye!="不限"){
$query.=" && wuye='".$wuye."'"; //物业类型 如住房,商铺
}
if($price2!=""){
switch($price1){
case "大于":
$query.=" && price>'".$price2."'"; //价格
break;
case "等于":
$query.=" && price='".$price2."'";
break;
case "小于":
$query.=" && price<'".$price2."'";
break;
}
}
if($area2!=""){
switch($area1){
case "大于":
$query.=" && area>'".$area2."'"; //面积
break;
case "等于":
$query.=" && area='".$area2."'";
break;
case "小于":
$query.=" && area<'".$area2."'";
break;
}
}
switch($pubdate){ //发布日期
case "本星期内":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=7";
break;
case "一个月内":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=30";
break;
case "三个月内":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=91";
break;
case "六个月内":
$query.=" && TO_DAYS(NOW()) - TO_DAYS(date)<=183";
break;
}
if($address!=""){
$query.=" && address like '%$address%'"; //地址
}
if(!$page){
$page=1;
}
?>
2、输出查询结果:
<?php
if ($page){
$page_size=20;
$result=mysql_query()($query);
#$message_count=mysql_result($result,0,"total");
$message_count=10;
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query=$query." order by date desc limit $offset, $page_size";
$result=mysql_query($query);
if($result){
$rows=mysql_num_rows($result);
if($rows!=0){
while($myrow=mysql_fetch_array($result)){
echo "<tr>";
echo "<td width='15' height='12'><img src='/blog_article/image/home2.gif' width='14' height='14'></td>";
echo "<td width='540' height='12'>$myrow[id] $myrow[tradetype] $myrow[address] $myrow[wuye]($myrow[housetype])<font >[$myrow[date]]</font>";
echo "</td>";
echo "<td width='75' height='12'><a href='/blog_article/view_d/code/$myrow[code].html' target='_blank'>详细内容</a></td>";
echo "</tr>";
}
}
else echo "<tr><td><div align='center'><img src='/blog_article/image/sorry.gif'><br><br>没有找到满足你条件的记录</div></td></tr>";
}
$prev_page=$page-1;
$next_page=$page+1;
echo "<div align='center'>";
echo " 第".$page."/".$page_count."页 ";
if ($page<=1){
echo "|第一页|";
}
else{
echo "<a href='/blog_article/$PATH_INFO/page/1.html'>|第一页|</a>";
}
echo " ";
if ($prev_page<1){
echo "|上一页|";
}
else{
echo "<a href='/blog_article/$PATH_INFO/page/$prev_page.html'>|上一页|</a>";
}
echo " ";
if ($next_page>$page_count){
echo "|下一页|";
}
else{
echo "<a href='/blog_article/$PATH_INFO/page/$next_page.html'>|下一页|</a>";
}
echo " ";
if ($page>=$page_count){
echo "|最后一页|";
}
else{
echo "<a href='/blog_article/$PATH_INFO/page/$page_count.html'>|最后一页|</a>";
}
echo "</div>";
}
else{
echo "<p align='center'>现在还没有房屋租赁信息!</p>";
}
echo "<hr width="100%" size="1">";
?>
</table>
希望本代码,可以帮助到大家。
有关php记录日志的文章,大家还可以参考下这二篇:
快速记录日志的php自定义函数
php记录错误日志
实现代码如下:
<?php
/**
记录Log日志的函数
by www.
*/
/* 用户定义变量 */
$logfile = "clf.log"; /*LOG文件写到那里 */
$timezone = "+0100"; /* Timezone correction */
$lookup_size = true; /* 设置文件的权限 */
$document_root = "/usr/local/apache/share/htdocs";
/* 他可能或不可能对相同的客户端记数
* 一定要对$document_root 这个变量进行设置才可以工作
*/
function write_to_log($str) {
if($fd = @fopen($GLOBALS[ "logfile"], "a")) {
fputs($fd, $str);
fclose($fd);
}
}
function get_var($name,$default) {
if($var = getenv($name)) {
return $var;
} else {
return $default;
}
}
if($remote_host = get_var( "REMOTE_HOST", false)) {
$remote_host = get_var( "REMOTE_ADDR", "-");
}
$remote_user = get_var( "REMOTE_USER", "-");
$remote_ident = get_var( "REMOTE_IDENT", "-");
$server_port = get_var( "SERVER_PORT", 80);
if($server_port!=80) {
$server_port = ":" . $server_port;
} else {
$server_port = "";
}
$server_name = get_var( "SERVER_NAME", "-");
$request_method = get_var( "REQUEST_METHOD", "GET");
$request_uri = get_var( "REQUEST_URI", "");
$user_agent = get_var( "HTTP_USER_AGENT", "");
if($lookup_size == true && $document_root) {
$filename = ereg_replace( "\?.*", "", $request_uri);
$filename = "$document_root$filename";
if(!$size = filesize($filename)) {
$size = 0;
}
} else {
$size = 0;
}
$date = gmdate( "d/M/Y:H:I:s");
$log = "$remote_host $remote_ident $remote_user [$date $timezone] \"".
"$request_method http://$server_name$server_port$request_uri\" 200 $size\n";
write_to_log($log);
?>