您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP遍历的有关问题?麻烦大家帮看一下

2024/3/5 14:17:02发布27次查看
php遍历的问题?麻烦大家帮看一下。
我有个方法从mysql中取出一组数据,可是用while,for,foreach遍历出来的数据都多了,麻烦各位给看一下
1:取结果的方法
php codefunction queryuserreport ( $userid ) { $resuserreportlist = ; $queryuserreport = select reportid, userid, reportcheckid, email, createtime, constitutiontype from userreport where userid = '.$userid.' ; //echo query:.$queryconstiutcontent.
; $resuserreportlist = $this->user_db->querysql ( $queryuserreport ) ; if ($resuserreportlist){ $resuserreportlist = $this->user_db->get_array($resuserreportlist); //print_r($resconstiutcontent); return $resuserreportlist ; } else { return $this->user_db->print_last_error(true); } $this->user_db->close() ; }
2:引用mysql的类
php code function querysql($sql){ $this->last_query=$sql; $result=mysql_query($sql); if (!$result){ $this->last_error=mysql_error(); return false; }else { $this->row_count=mysql_num_rows($result); return $result; } } function get_array($result){ if (!$result){ $this->last_error=invalid resource identifier passed to get_array() function.; return false; }else { $row=mysql_fetch_array($result); if ($row==false){ $this->last_error=mysql_error(); return false; }else { return $row; } } }
3:取出的结果
php codearray( [0] => 3 [reportid] => 3 [1] => 414 [userid] => 414 [2] => 201209021468 [reportcheckid] => 201209021468 [3] => [email] => [4] => 2012-02-09 11:30:54 [createtime] => 2012-02-09 11:30:54 [5] => 1 [constitutiontype] => 1)
4:页面获取数据代码
php code//获取数据$arrayuserreportlist = $dbconstitumodel->queryuserreport($_session['userid']);while ( $arrayuserreportlist = $arrayuserreportlist ){ echo ; echo .$arrayuserreportlist['reportid'].  ; echo .$arrayuserreportlist['createtime'].  ; echo 查看报告  ; echo
; }
------解决方案--------------------
mysql_fetch_array 改成用mysql_fetch_assoc()
------解决方案--------------------
$arrayuserreportlist = $dbconstitumodel->queryuserreport($_session['userid']);
echo ;
echo .$arrayuserreportlist['reportid'].  ;
echo .$arrayuserreportlist['createtime'].  ;
echo 查看报告  ;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product