Home >Backend Development >PHP Tutorial > 为何用WHILE不能遍历输出表

为何用WHILE不能遍历输出表

WBOY
WBOYOriginal
2016-06-13 12:40:46974browse

为什么用WHILE不能遍历输出表

<br />
一个很普通查询输出函数现在表中有10条数据<br />
调用的时候因为要把结果转成XML所以不能在函数体里做echo<br />
但是这样调用只能输出最后一条记录,求能在调用页面输出整表内容的方法<br />
<br />
调用<br />
echo main_shopactive();<br />
<br />
函数体<br />
function main_shopactive()<br />
{<br />
	//商场活动查询,返回逆向排序的最后一条活动记录<br />
	$conn = mysql_connect_conn();<br />
	$sql = "SELECT * FROM wx_active order by id desc limit 0,30";<br />
	$rs = mysql_db($sql,$conn) or die('查询记录失败!'); <br />
	if(mysql_num_rows($rs) > 0)<br />
	{<br />
		while($row = mysql_fetch_assoc($rs))<br />
		{<br />
			$my_active = $row['concent'];<br />
		}<br />
	}<br />
	else<br />
	{<br />
		$my_active = 'NO ACTIVE';<br />
	}<br />
	return $my_active;<br />
}<br />

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn