Forum Moderators: coopster
Anyone know why I am getting a "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result " error on this?
[php]
// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
$result = mysql_query($query);
while($r = mysql_fetch_assoc($result))
{
[/php]
// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
$result = mysql_query($query);
while($r = mysql_fetch_assoc($result))
{
You want:
// Get the student info from DB
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='$user'") or die(mysql_error());
while($r = mysql_fetch_assoc($query))
{
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
on this line:
while($r = mysql_fetch_assoc($query))
Put the mysql_query and mysql_fetch_assoc the way it was and
. .. replace this with the query:
$query = mysql_query("SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='". $user ."'") or die(mysql_error());
. . . put this line after it, that is for test and see how the query looks like when printed:
echo "SELECT student_id, type, guardianship , first_name, last_name, agent_number FROM students WHERE username='". $user ."'";
Hab
while($r=mysql_fetch_array($result))
while($r=mysql_fetch_array($query)) The other possible explaination is that you are overwritting the variable $query during your loop. There should not be anything written $query= within the while { } loop... if there is, change it to use another variable name ($queryb)
All the ones mentioned till, I have put them in one block. Can you try copying the following as it is, and see if you still get an error?
// Get the student info from DB
$query = "SELECT student_id, type, guardianship, first_name, last_name, agent_number FROM students WHERE username='". $user ."'";
$result = mysql_query($query);
while($rows = mysql_fetch_array($result))
{
"The other possible explaination is that you are overwritting the variable $query during your loop. There should not be anything written $query= within the while { } loop... if there is, change it to use another variable name ($queryb"
I had 2 other $query and $result Variables which I changed.
Thank you both so much for your help.