首页 > PHP教程

php入门级别的分页函数

function page($sql,$pagesize=10,$class=""){
 
 if(!is_string($sql)){ return 0;exit;}
 $result=mysql教程_query($sql);
 if(!$result){return 0;exit;}
 if(!$recordnum=mysql_num_rows($result)){return 0;exit;}
 $totalpage=ceil($recordnum/$pagesize);
 $page=(int)$_get['page'];
 if($page<=1) $page=1;
 if($page>=$totalpage) $page=$totalpage;
 $recordno=($page-1)*$pagesize;
 $sql.=" limit $recordno,$pagesize";
 $result=mysql_query($sql);
 $url=$_server["php_self"];

阅读全文

php搜索csv表格中是否存在指定数据

//搜索csv中指定内容

$fh = @fopen("csv_file_name", "r");
if($fh) {
   if(flock($fh, lock_ex)) {
      while(!feof($fh)) {
         $line = fgets($fh);
         if(strstr($line, $target_email_address) !== false) {
            $data = split(",", $line); // $data *is* an array
         }
      }
      flock($fh, lock_un);
   }

阅读全文

SupeSite利用join left联合查询出新闻表中带有图片附件记录

mysql教程_connect('localhost','root','root');
mysql_select_db('abc');
mysql_query("set names 'gbk'");

$sql = "select a.itemid,a.lastpost,a.city,b.thumbpath from supe_spaceitems  a left join supe_attachments  b on a.itemid = b.itemid where a.picid>0 order by a.itemid desc limit 0,3";
 
 $query  = mysql_query( $sql );
 while( $k = mysql_fetch_array( $query ) )
 {
  $str .= "<a href='/a/'".date("ymd",$k['lastpost']).'/v-'.$k['itemid'].".html><img src=".$url.'/attachments/'.$k['thumbpath']." /></a>";
 } 

阅读全文