Forum Moderators: coopster

Message Too Old, No Replies

second query inside the loop of the first query's results

         

eponymous

10:02 am on May 18, 2006 (gmt 0)

10+ Year Member



Firstly, hello! I'm very glad to have come across this forum, and have discovered several answers to my issues already. I'm hoping somebody can help me with this one.

Relevent bit of code:

$query = "SELECT * FROM SS_League WHERE ID='$session_uid' ORDER BY Name";
$results = mysql_query( $query, $link );
while( $myrow = mysql_fetch_array( $results ) ) {
$lid = $myrow[ "ID" ];
$lname = $myrow[ "Name" ];

$query_league = "SELECT * FROM SS_League" . $lid . " WHERE AgentID = '$session_uid'";
$results_league = mysql_query( $query_league, $link );
while( $myrow_league = mysql_fetch_array( $results_league ) ) { // This is line 33, see error below
$lworth = $myrow_league[ "Worth" ];
}
// Lines which output the variables in some html.
}

This is the error when I load the page:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in [file name] on line 33.

I've checked, and the problem is not the use of $lid in the second query. The error occurs even when I hard-code a table name into the query.

I feel as though I must be missing something obvious, but I'm totally stumped.

Thanks in advance. :)

dreamcatcher

10:09 am on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello eponymous, welcome to Webmaster World. :)

To receive that error the query must be failing. So we need to look at this line:

$results_league = mysql_query( $query_league, $link );

Change this to the following:

$results_league = mysql_query( $query_league, $link ) or die(mysql_error());

This should output the problem to the browser.

dc

eponymous

10:21 am on May 18, 2006 (gmt 0)

10+ Year Member



Ahh, that did indeed show the problem. I made a mistake in my logic.

I've not used die before, but I'll definitely be doing so in future. Very handy.

Thanks for such a swift and helpful response. :)

dreamcatcher

10:40 am on May 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anytime my friend. :)