1
$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

1

1 Answer 1

1

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++;
}
Sign up to request clarification or add additional context in comments.

3 Comments

@katates see my edit i missed something change fetch array to mysql_fetch_assoc
Thats weird now it only gets the first char, edit: solved it!
might because your table name is the same as your column name also do you have mysql_select_db("your data base name") line after you connected to the data base but before the query? and this line i believe should be this $result = mysql_query($query);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.