如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
数据库字段最值SQL语句如下:select字段from表where字段=(selectmax(字段)from表)SQL语句如下:select字段from表where字段=(selectmin(字段)from表)HYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"viewplainHYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"copytoclipboardHYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"printHYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"?<?php//连接数据库$myconn=mysql_connect("localhost","root","");mysql_select_db("nowamagic",$myconn);$strSql="selectarticle_IDfromarticlewherearticle_ID=(selectmax(article_ID)fromarticle)";$strSql2="selectarticle_IDfromarticlewherearticle_ID=(selectmin(article_ID)fromarticle)";$result=mysql_query($strSql,$myconn)ordie(mysql_error());$result2=mysql_query($strSql2,$myconn)ordie(mysql_error());$row_max=mysql_fetch_array($result);$row_min=mysql_fetch_array($result2);//输出ID最大值//echo$row_max["article_ID"];//echo"<br>";//输出ID最小值//echo$row_min["article_ID"];$article_count=$row_max["article_ID"]-$row_min["article_ID"];?>从数据库字段中查询出最大值,赋给$row_max;然后再查询出最小值,赋给$row_min;然后用最大值减去最小值再加1,就可以得出数据库记录的条数。这里从文章数据库article得出的是文章的数目。题外话若是单纯地求数据库的记录总数的话,其实用一条SQL语句就可以搞定的。HYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"viewplainHYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"copytoclipboardHYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"printHYPERLINK"http://www.nowamagic.net/database/db_MaxMinSQL.php"?<?php$conn=mysql_connect("localhost","root","")ordie("数据库连接错误".mysql_error());mysql_select_db("nowamagic",$conn)ordie("数据库访问错误".mysql_error());mysql_query("setnamesutf-8");$query="selectcount(*)astotalfromarticleorderbyarticle_IDdesc";$result=mysql_query($query);$message_count=mysql_result($result,0,"total");echo$message_count;?>运行结果如下:Warning:mysql_connect():Accessdeniedforuser'root'@'localhost'(usingpassword:NO)in/var/www/html/library/conn.phponline3Warning:mysql_select_db()expectsparameter2toberesource,booleang