$query = "SELECT * FROM pass";
$result = mysql_query($query,$conn);
echo mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
$username = $row['user'];
$password = $row['pass'];
}
Num rows = 12但是如果我使用while $row = mysql_fetch_array(mysql_query("SELECT * FROM pass",$conn))
如果我使用第一行代码,它会在第一行后出错, 警告:mysql_fetch_array()要求参数1为资源,字符串在
中给出答案 0 :(得分:1)
你定义变量是错误的,如果你不给它一个数字它总是只有1个结果并做一些关于连接到mysql数据库的新方法的阅读
$i = 0;
while($row = mysql_fetch_assoc($result))
{
$username[$i] = $row['user'];
$password[$i] = $row['pass'];
$i++;
}
//you can test like this
$r = 0;
while($r < $i)
{
echo $username[$r];
echo $password[$r];
$r++;
}