我有个方法从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 查看报告 ;
