Reputation: 23
$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 but while loops only the first one if I use in while $row = mysql_fetch_array(mysql_query("SELECT * FROM pass",$conn))
If i use the first code it gives error after the first row, Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in
Upvotes: 1
Views: 794
Reputation: 370
you define the variables wrong if you don't give it a number it will always only have 1 result and do some reading about newer ways to connect to mysql database
$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++;
}
Upvotes: 1