扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
mysql:SELECT * FROM table order by rand() limit 10;
成都创新互联是专业的保亭黎族网站建设公司,保亭黎族接单;提供成都网站制作、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行保亭黎族网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
从数据库随机取出来之后再用php处理一下,按照你的需求再排序咯。然后楼主还有什么疑问的话,还不懂,可以去后盾人看看,里面有些资料,兴许能够帮助你
$sql = "SELECT * FROM chat WHERE id ".$lastID." ORDER BY id ASC LIMIT 60";
改为
$sql = "SELECT * FROM chat WHERE id ".$lastID." ORDER BY id ASC LIMIT 0,10";
你给出的数据组织形式,貌似是json,那么你可以直接用json_encode() 和 json_decode()进行转换后,再进行处理。
示例代码:
?php
$json = '{
"6846": {
"userid": "6846",
"expertname": "三剑客",
"firstrate": "0",
"wrong": null,
"firstqs": "2011254",
"firstvalue": "2",
"lastrate": "0",
"firstnum": "0",
"lastnum": "0",
"kjtime": "2012-09-30 00:00:00",
"successrate": "0",
"curqs": " (2012267,2012266,2012262,2012259,2011256,2011255,2011254 )",
"lastpaiming": "1",
"curpaiming": "1"
},
"9205": {
"userid": "9205",
"expertname": "东方诸葛",
"firstrate": "0",
"wrong": null,
"firstqs": "2011254",
"firstvalue": "2",
"lastrate": "0",
"firstnum": "0",
"lastnum": "0",
"kjtime": "2012-09-30 00:00:00",
"successrate": "0",
"curqs": " (2012267,2012266,2012262,2012259,2011256,2011255,2011254 )",
"lastpaiming": "2",
"curpaiming": "2"
},
"9213": {
"userid": "9213",
"expertname": "神探老李",
"firstrate": "0",
"wrong": null,
"firstqs": "2011254",
"firstvalue": "2",
"lastrate": "0",
"firstnum": "0",
"lastnum": "0",
"kjtime": "2012-09-30 00:00:00",
"successrate": "0",
"curqs": " (2012267,2012266,2012262,2012259,2011256,2011255,2011254 )",
"lastpaiming": "3",
"curpaiming": "3"
},
"17518": {
"userid": "17518",
"expertname": "草原雄鹰",
"firstrate": "0",
"wrong": null,
"firstqs": "2011254",
"firstvalue": "2",
"lastrate": "0",
"firstnum": "0",
"lastnum": "0",
"kjtime": "2012-09-30 00:00:00",
"successrate": "0",
"curqs": " (2012267,2012266,2012262,2012259,2011256,2011255,2011254 )",
"lastpaiming": "4",
"curpaiming": "4"
}
}';
echo 'Pre';
print_r( json_decode($json,true) );
echo '/pre';
?
先找出状态=1的最大cid:X,然后搜索cid = X的那一行:
select name from 表名 where cid = (select max(cid) from 表名 where status=1) 其中status类型要为int
如果是varchar,就要写成status='1'
按照楼主已死贴出完整代码,看不懂再问
$sql="select * from `user` order by `id` desc";//自己随便写一个sql语句测试用,根据自己需求替换,不要加limit
$pagesize=10;
$num=mysql_num_rows(mysql_query($sql));
$pagecount=ceil($num/$pagesize);
$pageall=$num;
if(!isset($_GET["page"])){//这里翻页模式用GET方式传参解决,?page=1的方式
$pageindex="1";
}else{
$pageindex=$_GET["page"];
if($pageindex==""){
$pageindex="1";
}elseif(!is_numeric($pageindex)){
$pageindex="1";
}elseif(substr_count($pageindex,".")!=0){
$pageindex="1";
}elseif($pageindex$pagecount){
$pageindex=$pagecount;
}elseif($pageindex=1){
$pageindex="1";
}
}
if($pageindex$pagecount){
$start=($pageindex-1)*$pagesize;
$sql1=$sql." limit ".$start.",".$pagesize;
}else{
if($num%$pagesize!=0){
$start=($pageindex-1)*$pagesize;
$sql1=$sql." limit ".$start.",".($num%$pagesize);
}else{
$start=($pageindex-1)*$pagesize;
$sql1=$sql." limit ".$start.",".$pagesize;
}
}
$result=mysql_query($sql1);
while($RS = @mysql_fetch_array($result)){
//按要求读出每次循环的字段
}
明白你的意思了。
$a = mysql_query("select * from table_name", $link); //这个地方你的写法有问题,两个参数外不需要加引号,我的是正确的
这个$a只是mysql一个资源集,你要用mysql_fetch_array这个函数循环从里面提取数据,具体可以查手册mysql_fetch_array的用法,完整代码是:
$a = mysql_query("select * from table_name", $link);
while ( $row = mysql_fetch_array($a) )
{
print_r($row); //$row 就是一行数据,是一个数组
}
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流