当前位置: 编程技术>php
本页文章导读:
▪php读取30天之内的根据算法排序的代码
代码如下:<?php $link=mysql_connect("","","") or die("无法连接到mysql数据库".mysql_error()); mysql_select_db("duyounet",$link); mysql_query("SET NAMES 'gb2312'",$link); $day30=time()-60*60*24*30; $result=mysql_query("select article.........
▪PHP实现Socket服务器的代码
<?php ob_implicit_flush(); set_time_limit(0); $address = "192.40.7.93";//换成你自己的地址 $port = 10000; if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false) echo "错误(socket_create):".socket_strerror(socket.........
▪mysql+php分页类(已测)
代码如下:<?php /* mysql_pager.class.php 三个参数。 mysql_query()的结果, url变量page, 您要的每页记录数 例子在这个文件底部 淡水河边整理测试 */ .........
[1]php读取30天之内的根据算法排序的代码
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
$link=mysql_connect("","","")
or die("无法连接到mysql数据库".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("查询".$database."数据库出错".mysql_error());
$row=mysql_fetch_row($result);
echo "document.writeln(\"<ul >\")".";\r\n";
while ($row){
echo "document.writeln(\"<li><a href='/modules/article/articleinfo/id/.html".$row[0]."' target='_blank'>".$row[1]."(".$row[2].")</a></li>\");\r\n";
$row=mysql_fetch_row($result);
}
mysql_free_result($result);
mysql_close();
echo "document.writeln(\"</ul>\");\r\n"
?>
substr()
把月份取出+了在放回去
偶是这么做的有更好的方法记得告诉偶
嘿嘿~
作者: 太阳雨 发布日期: 2005-4-13
如果在PHP中处理,用strtotime
[php]
$a="2004/11/01";
$b=strtotime("+6 months",strtotime($a));
echo date('Y/m/d',$b);
[/php]
如果在mysql中处理,用DATE_ADD或ADDDATE函数,也可以直接使用INTERVAL关键字
如:
1、SELECT "2004-11-01" + INTERVAL 6 MONTH;//其中的2004-10-01可以直接使用日期字段
2、SELECT DATE_ADD("2004-11-01", INTERVAL 6 MONTH);
[2]PHP实现Socket服务器的代码
来源: 互联网 发布时间: 2013-11-30
<?php
ob_implicit_flush();
set_time_limit(0);
$address = "192.40.7.93";//换成你自己的地址
$port = 10000;
if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false)
echo "错误(socket_create):".socket_strerror(socket_last_error())."<br />";
if(socket_bind($socket,$address,$port) == false)
echo "错误(socket_bind):".socket_strerror(socket_last_error())."<br />";
if(socket_listen($socket) == false)
echo "错误(socket_listen):".socket_strerror(socket_last_error())."<br />";
/*
After the socket socket has been created using socket_create() and bound to a name with socket_bind(),
it may be told to listen for incoming connections on socket.
*/
while(true){
if(($msgSocket = socket_accept($socket)) == false){
echo "错误(socket_accept):".socket_strerror(socket_last_error())."<br />";
break;
}
/*
this function will accept incoming connections on that socket.
Once a successful connection is made, a new socket resource is returned, which may be used for communication.
If there are multiple connections queued on the socket, the first will be used.
If there are no pending connections, socket_accept() will block until a connection becomes present.
If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned.
*/
$msg = "Welcome!<br />";
//socket_write($msg,$msg,strlen($msg));
$command = "";
while(true){
if(($buf = socket_read($msgSocket,2048,PHP_BINARY_READ)) == false){
echo "错误(socket_read):".socket_strerror(socket_last_error())."<br />";
break 2;
}
/*
The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions.
The maximum number of bytes read is specified by the length parameter.
Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).
*/
/*
if(!$buf = trim($buf))
continue; // ????
if($buf == "quit")
break;
if($buf == "shutdown"){
socket_close($msgSocket);
break 2;
}
$tallBack = "You say:$buf\n";
socket_write($msgSocket,$tallBack,strlen($tallBack));
*/
if(ord($buf) != 13)
$command .= $buf;
else{
$command1 = "You Say:$command\r\n";
socket_write($msgSocket,$command1,strlen($command1));
echo "User typed:".$command."<br />";
$command = "";
}
}
socket_close($msgSocket);
}
socket_close($socket);
?>
然后打开CMD,输入:telnet 192.40.7.93 10000,自己体验去吧!
注,要把:php_sockets.dll 打开
ob_implicit_flush();
set_time_limit(0);
$address = "192.40.7.93";//换成你自己的地址
$port = 10000;
if(($socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP)) == false)
echo "错误(socket_create):".socket_strerror(socket_last_error())."<br />";
if(socket_bind($socket,$address,$port) == false)
echo "错误(socket_bind):".socket_strerror(socket_last_error())."<br />";
if(socket_listen($socket) == false)
echo "错误(socket_listen):".socket_strerror(socket_last_error())."<br />";
/*
After the socket socket has been created using socket_create() and bound to a name with socket_bind(),
it may be told to listen for incoming connections on socket.
*/
while(true){
if(($msgSocket = socket_accept($socket)) == false){
echo "错误(socket_accept):".socket_strerror(socket_last_error())."<br />";
break;
}
/*
this function will accept incoming connections on that socket.
Once a successful connection is made, a new socket resource is returned, which may be used for communication.
If there are multiple connections queued on the socket, the first will be used.
If there are no pending connections, socket_accept() will block until a connection becomes present.
If socket has been made non-blocking using socket_set_blocking() or socket_set_nonblock(), FALSE will be returned.
*/
$msg = "Welcome!<br />";
//socket_write($msg,$msg,strlen($msg));
$command = "";
while(true){
if(($buf = socket_read($msgSocket,2048,PHP_BINARY_READ)) == false){
echo "错误(socket_read):".socket_strerror(socket_last_error())."<br />";
break 2;
}
/*
The function socket_read() reads from the socket resource socket created by the socket_create() or socket_accept() functions.
The maximum number of bytes read is specified by the length parameter.
Otherwise you can use \r, \n, or \0 to end reading (depending on the type parameter, see below).
*/
/*
if(!$buf = trim($buf))
continue; // ????
if($buf == "quit")
break;
if($buf == "shutdown"){
socket_close($msgSocket);
break 2;
}
$tallBack = "You say:$buf\n";
socket_write($msgSocket,$tallBack,strlen($tallBack));
*/
if(ord($buf) != 13)
$command .= $buf;
else{
$command1 = "You Say:$command\r\n";
socket_write($msgSocket,$command1,strlen($command1));
echo "User typed:".$command."<br />";
$command = "";
}
}
socket_close($msgSocket);
}
socket_close($socket);
?>
然后打开CMD,输入:telnet 192.40.7.93 10000,自己体验去吧!
注,要把:php_sockets.dll 打开
[3]mysql+php分页类(已测)
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
/*
mysql_pager.class.php
三个参数。 mysql_query()的结果, url变量page, 您要的每页记录数
例子在这个文件底部
淡水河边整理测试
*/
class mysql_pager {
// define properties
var $page;
var $result;
var $results_per_page = 3;
var $total_pages;
/*
Define the methods
下面是构造函数,和类同名(>php4)
需要查询的结果句柄,当前页码,每页记录数
like: $f->mysql_pager($result, 1, 15);
*/
function mysql_pager( $result, $current_page, $results_per_page ) {
if(!$result){
echo "<div align=center>数据库未运行,结果集错误</div>\n";
return;
}
$this->result = $result;
if(!$current_page || $current_page < 0)
$this->page = 1;
else $this->page = $current_page;
if(!emptyempty($results_per_page))
$this->results_per_page = $results_per_page;
$numrows = @mysql_num_rows($this->result);
if(!$numrows) {
echo "<div align=center>查询结果为空.</div>\n";
return;
}
$this->total_pages = ceil($numrows / $this->results_per_page);
}
/*
下面是打印内容的函数,可以不用,也可以根据自己的需要扩展
这里只是打印出id
*/
function print_paged_results() {
echo "<table border=0 align=center>\n";
$start = ($this->page - 1) * $this->results_per_page;
mysql_data_seek($this->result, $start);
$x = 0;
for($i = 1; $i <= $this->results_per_page && $row = @mysql_fetch_array($this->result); $i++) {
if($x++ & 1) $bgcolor = "#F2F2FF";
else $bgcolor = "#EEEEEE";
echo "<tr bgcolor=$bgcolor><td>". $row["id"] . "</td></tr>";
// 编辑这部分输出任何您想要的HTML
}
echo "</table>\n";
}
/*
下面是打印页码和链接的函数
在我们需要显示页码的地方调用
*/
function print_navigation() {
global $PHP_SELF;
echo "<div align=center>";
for($i = 1; $i <= $this->total_pages; $i++) { #loop to print << 1 2 3... $total_pages >>
if($i == 1 && $this->page > 1) #Prints the << first to goto the previous page (not on page 1)
echo "<a href=/index.html"$PHP_SELF?page=".($this->page - 1)."\" onMouseOver=\"status="Previous Page";return true;\" onMouseOut=\"status=" ";return true;\">?</a>";
if($i == $this->page) #Doesn"t print a link itself, just prints page number
echo "<font color=\"#ff3333\"> $i </font>";
if($i != $this->page) #Other links that aren"t this page go here
echo "<a href=/index.html"$PHP_SELF?page=$i\" onMouseOver=\"status="Go to Page $i";return true;\" onMouseOut=\"status=" ";return true;\"> $i </a>";
if($i == $this->total_pages && $this->page != $this->total_pages) # Link for next page >> (not on last page)
echo "<a href=/index.html"$PHP_SELF?page=".($this->page + 1)."\" onMouseOver=\"status="Go to the Next Page";return true;\" onMouseOut=\"status=" ";return true;\">?</a>";
}
echo "</div>\n";
}
}
/*
mysql_connect($server, $uname, $pass );
mysql_select_db("$db");
$result= @mysql_query("Select * FROM table");
$p = new mysql_pager( $result, $page=$_GET["page"], 10 );
$p->print_navigation();
$p->print_paged_results();
$p->print_navigation();
*/
?>
最新技术文章: