Home  >  Article  >  Backend Development  >  PHP reads the codes sorted according to the algorithm within 30 days

PHP reads the codes sorted according to the algorithm within 30 days

WBOY
WBOYOriginal
2016-07-29 08:37:43924browse

Copy code The code is as follows:


$link=mysql_connect("","","")
or die("Unable to connect to mysql database".mysql_error());
mysql_select_db("duyounet",$link);
mysql_query("SET NAMES 'gb2312'",$link);
$day30=time()-60*60*24*30;
$result=mysql_query("select articleid ,articlename, (allvote*20+goodnum+allvisit) as dxy_px from jieqi_article_article where postdate>$day30 order by dxy_px desc limit 0,14") or die("query".$database."database error".mysql_error()) ;
$row=mysql_fetch_row($result);
echo "document.writeln("

    ")".";rn";
    while ($row){
    echo "document. writeln("
  • ".$row[1]." (".$row[2].")
  • ");rn";
    $row=mysql_fetch_row($result);
    }
    mysql_free_result($result);
    mysql_close() ;
    echo "document.writeln("
");rn"
?>


substr()
Take out the month + put it back again
I think there is a better way to remember this Tell me
hehe~
Author: Taiyangyu Release date: 2005-4-13
If processing in PHP, use strtotime
[php]
$a="2004/11/01";
$b=strtotime(" +6 months",strtotime($a));
echo date('Y/m/d',$b);
[/php]
If processed in mysql, use DATE_ADD or ADDDATE function, or you can use it directly INTERVAL keyword
For example:
1. SELECT "2004-11-01" + INTERVAL 6 MONTH;//The date field 2004-10-01 can be used directly
2. SELECT DATE_ADD("2004-11-01", INTERVAL 6 MONTH);

The above introduces PHP to read the code sorted according to the algorithm within 30 days, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn