PHP ·ÖÒ³
·ÂGOOGLEºÍDiscuz·ÖÒ³º¯Êý(php)
Õâ¸öº¯ÊýÖ»ÐèÒª2¸ö²ÎÊý µ±Ç°Ò³ÂëºÍ×ÜÒ³Êý,$siteÊÇ·¾¶,ÎļþÃû¿ÉÒÔ°´×Ô¼ºµÄÐèÒªÐÞ¸Ä
Õâ¸öº¯Êý²»ÄÜ´«µÝÆäËû²ÎÊý,Èç¹ûÒª´«µÝÆäËû²ÎÊý,ÔÚº¯ÊýÀï×Ô¼º¼ÓÒ»¸ö²ÎÊý¾ÍÐÐÁË
<?php
//¼ÆÊý
$sql = “SELECT count(*) from `andycms_title`;”;
$numrs = mysql_query($sql) or die(mysql_error());
$numrow = mysql_fetch_row($numrs);
$num = $numrow[0]; //×ܼǼ
$total = ceil($num / $perpage); //×ÜÒ³Êý
//µ±Ç°Ò³Âë
if(!isset($_GET[‘page’]) preg_match(‘~[^0-9]+~’,($_GET[‘page’])) $_GET[‘page’] <= 0 $_GET[‘page’] > $total) $page = 1;
else $page = $_GET[‘page’];
$startnum = ($page-1) * $perpage; //¼Ç¼¼¯¿ªÊ¼Êý
?>
<?php
// Andy·ÖÒ³º¯Êý
function fenye ($p,$total)
{
global $site;
$prevs = $p - 10; if ( $prevs <= 0) { $prevs = 1; }
$prev = $prevs - 1; if ( $prev <= 0) {$prev = 1;}
$nexts = $p + 9; if ( $nexts > $total) { $nexts = $total; }
$next = $nexts + 1; if ( $next > $total) {$next = $total;}
$pagenavi = “<a href=\”$site/?page=1\”>Ê×Ò³</a> “;
$pagenavi.= “<a href=\”$site/?page=$prev\”>ÉÏÒ³</a> “;
for ( $i = $prevs; $i <= $p-1; $i++ ) {
$pagenavi.= “<a href=\”$site/?page=$i\”>$i</a> “;
}
$pagenavi.= “<strong>$p</strong> “;
for ( $i = $p+1; $i <= $nexts; $i++ ) {
$pagenavi.= “<a href=\”$site/?page=$i\”>$i</a> “;
}
$pagenavi.= “<a href=\”$site/?page=$next\”>ÏÂÒ³</a> “;
$pagenavi.= “<a href=\”$site/?page=$total\”>βҳ</a> “;
return $pagenavi;
}
?>
Ч¹û:
page=1
Ê×Ò³ ÉÏÒ³ 1 2 3 4 5 6 7 8 9 10 ÏÂÒ³ βҳ
page=10
Ê×Ò³ ÉÏÒ³ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ÏÂÒ³ βҳ
page=20
Ê×Ò³ ÉÏÒ³ 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Ïà¹ØÎĵµ£º
×î½üÔÚдһ¸ö ǰ̨»ùÓÚ javascript. µÄ¿Í»§¶Ë ·þÎñÆ÷¶ËPHP µÄ·ÖÎöϵͳ¡£
ÔÏȼƻ®Ê¹ÓÃXMLΪÊý¾Ý½»»¥»ù´¡ µ«ÊÇ×îÖÕ»¹ÊÇÑ¡ÓýÏÇáÁ¿¼¶µÄJSON×îΪÊý¾Ý½»»¥»ù´¡¡£
Ê×ÏȽéÉÜjsonµÄ¸ñʽ
json ˵¼òµ¥ÆäʵÊÇÒ»ÖÖÊý¾Ý¸ñʽ ¸ü¼òµ¥µÄ¿ÉÒÔ¿´×ö¼òµ¥µÄÊý×é¡£
ʵÀý £¨Ò»£©
<script>
var jsonArray=[
......
phpÁ¬½Ómysql²âÊÔ´úÂ룺
$link=mysql_connect('localhost','root','123456');
if(!$link) echo "ʧ°Ü!";
else echo "³É¹¦!";
mysql_close();
?>
ÔËÐдúÂë³öÏÖ£ºCall to undefined function 'mysql_connect()'… ʧ°Ü
°Ù¶ÈÕÒµ½½á¹ûÊÇPHP+MYSQL »·¾³Ã ......
ÕýÔò±í´ïʽ×Ô¼ºÒ»Ö±²»ÊìϤ£¬Õâ2ÌìÔÚÍøÉÏÒ»Ö±¿´¹ØÓÚËüµÄÎÄÕ£¬×Ô¼º×ܽáÁ˼¸¸öº¯Êý¡£
1£®preg_match()
º¯ÊýÔÐÍ£ºint preg_match (string $pattern, string $content [, array
$matches])
preg_match
()º¯ÊýÔÚ$content×Ö·û´®ÖÐËÑË÷Óë$pattern¸ø³öµÄÕýÔò±í´ïʽÏàÆ¥ÅäµÄÄÚÈÝ¡£Èç¹ûÌṩÁË$matches£¬Ôò½«Æ¥Åä½á¹û·ÅÈëÆäÖС ......
<?php
function delfile($dir,$n) //ɾ³ýDIR·¾¶ÏÂNÌìǰ´´½¨µÄËùÓÐÎļþ;
{
if(is_dir($dir))
{
if($dh=opendir($dir))
{
while (false !== ($file = readdir($dh)))
{
if($file!="." && $file!="..")
{
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) ......
/ ok
header('HTTP/1.1 200 OK');
//ÉèÖÃÒ»¸ö404Í·:
header('HTTP/1.1 404 Not Found');
//ÉèÖõØÖ·±»ÓÀ¾ÃµÄÖØ¶¨Ïò
header('HTTP/1.1 301 Moved Permanently');
//תµ½Ò»¸öеØÖ·
header('Location: http://www.example.org/'
);
//ÎļþÑÓ³ÙתÏò:
header('Refresh: 10; url=http://www.example.org/');
print 'Y ......