请问下php的Resource有关问题

WBOY
Release: 2016-06-13 11:47:02
Original
879 people have browsed it

请教下php的Resource问题?

<?php<br />header("Content-type: text/html; charset=utf-8"); <br />  if(!empty($_POST['username'])){<br />  $name=$_POST['username'];<br />}<br />  if(!empty($_POST['pwd'])){<br />  $pwd=$_POST['pwd'];<br />}  <br />  function sqlDql($name,$pwd){<br />  $conn=mysql_connect("localhost","root","root");<br />  if(!$conn){<br />  die("连接失败".mysql_error());<br />  }<br />  mysql_select_db("test",$conn) or die(mysql_error());<br />  //设置字符集<br />    mysql_query("set names utf8");<br />  $sql="select * from zhuche;";<br />    $res=mysql_query($sql,$conn) or die(mysql_error());<br />    while($row=mysql_fetch_row($res)){   <br />       if($name==$row[1]){<br />       	echo "用户名已经存在<br/>";<br />       	echo "<a href='login.php'>返回注册页面</a>";  <br />      // die(mysql_free_result($res)."连接".mysql_close($conn));<br />        mysql_free_result($res);  <br />        mysql_close($conn);<br />        exit();    	    <br />      }    <br />   }<br />    $sql2="insert into zhuche (Username,password) values ('".$name."','".$pwd."');";<br />    $res2=mysql_query($sql2,$conn) or die(mysql_error());<br />    echo "<table border='1px solid black'>";<br />    echo "<tr><td>序号</td><td>用户</td><td>密码</td></tr>";<br />    while($row=mysql_fetch_row($res)){<br />     	echo "<tr>";<br />     	foreach($row as $key=> $val){<br />     	 echo "<td>--".$val."</td>";<br />     	 }<br />     	echo "</tr>";<br />     	}<br />    echo "</table>";	 <br />    mysql_free_result($res);  <br />    mysql_close($conn);<br />  }<br />  sqlDql($name,$pwd);<br />?><br />
Copy after login
如果在第一个while没有退出 为什么下面的$res取不出数据?SQL语句出的问题没问题。
输出结果是


------解决方案--------------------
噢,看错了

但是 $res 经 while($row=mysql_fetch_row($res)){ 后已经指向结果集的尾部了
你需要用 mysql_data_seek($res, 1); 回绕结果集 
不过请注意:即便回绕了,也不会输出 mysql_query($sql2,$conn) 插入的值

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template