Php 显示函数返回的mySQL结果数组中的数据
我想从函数中传递一个mySQL结果并打印数据。 如何做到这一点Php 显示函数返回的mySQL结果数组中的数据,php,mysql,resultset,Php,Mysql,Resultset,我想从函数中传递一个mySQL结果并打印数据。 如何做到这一点 <?php function showLatestItems() { $result = $this->query("SELECT aid,name,description,img,amount,strtdate,enddate FROM item WHERE enddate>now()"); return $result; /* while($row=mysql_fetch_array($re
<?php
function showLatestItems()
{
$result = $this->query("SELECT aid,name,description,img,amount,strtdate,enddate FROM item WHERE enddate>now()");
return $result;
/* while($row=mysql_fetch_array($result))
echo $row[0].' '.$row[3].' '.$row[1].' '.$row[2].$row[4].$row[5].$row[6].'<br>';
*/
}
?>
只需捕获结果资源,然后从中获取行。根据注释掉的代码,我们假设您已使用名为
query()
的类方法包装了mysql\u query()
我讨厌var_dump,请友善点:P@Sourav
var_dump()
仅用于证明$rowset
是一个数组。警告:为foreach()@Sourav提供的参数无效。什么foreach
?你的代码和我的代码都没有。
$result = $yourclass->showLatestItems();
if ($result) {
$rowset = array();
while ($row = mysql_fetch_assoc($result)) {
$rowset[] = $row;
}
}
var_dump($rowset);