I'm getting the following error messages when running my script:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ** on line 77
I have been reading from a MySQL database. Here is the code in context:
db_connect();
$col = 'level' . $access;
// $access is a variable already set, representing the user's access level
$result = mysql_query ( "SELECT * FROM bf_pages WHERE type = 'a'" );
if ( ! $result )
{
print_error_message( 'Database query failed. Please try again later, and if the problem persists, contact me.' );
}
$num_results = mysql_num_rows ( $result );
echo "<b>$num_results</b>";
while ( $result_array = mysql_fetch_array( $result ) )
{
$id = $result_array['id'];
echo "$id<br/>"; // debugging
$query = mysql_query( "select $col from bf_access where page = '$id'" );
if ( ! $query )
{
print_error_message( 'Not working as usual.' );
}
$result = mysql_fetch_array ( $query );
$url = $result_array['url'];
$mask = $result_array['mask'];
$link_array[] = link_ize ( $url, $mask );
}
I am basically trying to read rows from a MySQL database in a loop.
My database currently has two rows which need to be read, but for the first of these I get the error message. The strange thing is that the script works for the second row.
Can you help?