返回处理结果以及释放内存,基础练习。

函数mysql_fetch_array()   mysql_free_result()   mysql_close()

mysql_fetch_array() 返回根据从结果集取得的行生成的数组,如果没有更多行则返回false.

<html>
<head><meta http-equiv='content-type' content='text/html;charset=gb2312'></head>
<body>
<?php
$link=mysql_connect('localhost','root','123');
$select=mysql_select_db('madb',$link);
mysql_query('set names gb2312');
$str="select*from admin";
$res=mysql_query($str);
echo "内存释放前:<br/>";
echo "<table border='1' width='300px'>";
while($result=mysql_fetch_array($res))//mysql_fetch_array()函数返回从结果集取得的行生成的数组,
                                     //如果没有更多行则返回false
{
echo "<tr>";//开始的时候这里不理解,现在知道了:while括号里是把函数得到的数组赋值给$result,
echo "<td>".$result['id']."</td>"; //然后$result['id']就是二维数组$result里面键名id的一个数组。
echo "<td>".$result['name']."</td>";//把他们放在表格的列里面自然就是一列。
echo "<td>".$result['pwd']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_free_result($res);//释放内存
echo "内存释放后:<br/>";
while($result=mysql_fetch_array($res))
{
echo "<tr>";
echo "<td>".$result['id']."</td>";
echo "<td>".$result['name']."</td>";
echo "<td>".$result['pwd']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($link);//关闭数据库链接
?>
</body>
</html>

 

 

posted @ 2014-03-12 20:39  选择了就坚持  阅读(134)  评论(0编辑  收藏  举报