PHP traversal problems? Please take a look.

Source: Internet
Author: User
PHP traversal problems? Please take a look. I have a method to retrieve a group of data from mysql, but there are too many data retrieved by using the while, for, and foreach methods. please take a look at 1: method for retrieving results PHPcodefunctionqueryUserReport ($ PHP traversal problem? Please take a look.
I have a method to retrieve a group of data from mysql, but there are too many data retrieved by using the while, for, and foreach methods. please take a look.
1: method for obtaining results
PHP code
  function 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: Reference mysql class
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: Result
PHP code
  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: Get data code on the page
PHP code
  // Get Data $ arrayUserReportList = $ dbConstituModel-> queryUserReport ($ _ SESSION ['userid']); while ($ arrayUserReportList = $ arrayUserReportList) {echo""; Echo"". $ ArrayUserReportList ['recordtid'].""; Echo"". $ ArrayUserReportList ['createtime'].""; Echo"View reports"; Echo"";}


------ Solution --------------------
Change mysql_fetch_array to mysql_fetch_assoc ()
------ Solution --------------------
$ ArrayUserReportList = $ dbConstituModel-> queryUserReport ($ _ SESSION ['userid']);

Echo"";
Echo"". $ ArrayUserReportList ['recordtid']."";
Echo"". $ ArrayUserReportList ['createtime']."";
Echo"View reports";

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.