Jump to content

I'm getting an "invalid argument" error for my While loop....


Recommended Posts

I'm getting an invalid argument error for my While loop.  I can't figure out why. 

 

$sql="SELECT * FROM schools ORDER BY class DESC,sectional ASC,team ASC";

$results = mysql_query($sql);

while ($team = mysql_fetch_assoc($results)) {

echo $team['school'] . '<br>';

}

 

 

Here is the error:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/******/public_html/hoosierhoopsmagazine.com/resources/sectional_assignments.php on line 7

You know what they say about assumption being the mother of all f**k ups? Always check for errors when you execute a query:

 

$results = mysql_query($sql) or trigger_error('MySQL error: ' . mysql_error());

perhaps I am misunderstanding the documentation.. debugging your query is always the first step.. using code like Adam posted.. once you receive an error it will make it easier to remedy this..

Even with Adam's code, it produces:

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/jwrbloom/public_html/hoosierhoopsmagazine.com/resources/sectional_assignments.php on line 7

 

okay i don't think you're understanding.. lets try something more simple..

 

$sql="SELECT * FROM schools ORDER BY class DESC,sectional ASC,team ASC";

$results = mysql_query($sql) or die(mysql_error());

while ($team = mysql_fetch_assoc($results)) {

echo $team['school'] . '<br>';

}

I am understanding.  I put the exact code Adam told me to put, and that was what it produced, which is what I posted in the response above.

 

Yeah sorry for the confusion, I missed out E_USER_ERROR for the second parameter. If you didn't see the MySQL error though it's likely you have warning messages hidden.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.