• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-23) 21次浏览 已收录 0个评论

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

PHP code

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

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

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

<!---ecms 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>查看报告 </td>";                        echo "</tr>";                    }

——解本文来源gao.dai.ma.com搞@代*码#网搞代gaodaima码决方案——————–
mysql_fetch_array 改成用mysql_fetch_assoc()
——解决方案——————–
$arrayUserReportList = $dbConstituModel->queryUserReport($_SESSION[‘userid’]);

echo “

“;
echo “

“.$arrayUserReportList[‘reportId’].”

“;
echo “

“.$arrayUserReportList[‘createtime’].”

“;
echo “

查看报告

“;


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP遍历的有关问题?麻烦大家帮看一下

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址