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

WBOY
풀어 주다: 2016-06-13 13:46:52
원래의
858명이 탐색했습니다.

PHP遍历的问题?麻烦大家帮看一下。
我有个方法从mysql中取出一组数据,可是用while,for,foreach遍历出来的数据都多了,麻烦各位给看一下
1:取结果的方法

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
function queryUserReport ( $userid ) {
            
            $resUserReportList = "" ;

            $queryUserReport = "Select reportId, userid, reportCheckId, email, createtime, constitutiontype From userreport Where userid = '".$userid."' " ;
            //echo "query:".$queryConstiutContent."<br>";

            $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
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
 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 code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
Array
(
    [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
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
//获取数据
$arrayUserReportList = $dbConstituModel->queryUserReport($_SESSION['userid']);

while ( $arrayUserReportList = $arrayUserReportList ){
                        echo "<tr>";
                        echo "<td>".$arrayUserReportList['reportId']." </td>";
                        echo "<td>".$arrayUserReportList['createtime']." </td>";
                        echo "<td>
<a href="%5C%22/constest/constitutionreport/myreport_%22.%24arrayUserReportList%5B'reportCheckId'%5D.%22.html%5C%22" target='\"_blcnk\"'>查看报告</a> </td>";
                        echo "</tr>";
                    }

로그인 후 복사


------解决方案--------------------
mysql_fetch_array 改成用mysql_fetch_assoc()
------解决方案--------------------
$arrayUserReportList = $dbConstituModel->queryUserReport($_SESSION['userid']);

echo "";
echo "".$arrayUserReportList['reportId']." ";
echo "".$arrayUserReportList['createtime']." ";
echo " 查看报告 ";
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!