I want to know the total number of rows being returned by the following query $sql = "SELECT * FROM " . ADR_LIBRARY_TABLE ." WHERE book_difficulty <= $book_difficulty AND book_zone = $area_id"; $result = $db->sql_query($sql); if( !$result ) { message_die(GENERAL_ERROR, 'Could not obtain book information', "", __LINE__, __FILE__, $sql); } $library = $db->sql_fetchrow($result); PHP: I thought that mysql_num_rows($library); PHP: would return this, but it causes an error mysql_num_rows(): supplied argument is not a valid MySQL result resource Code (markup):
Never mind, think I see what I was doing wrong. Should have used this instead mysql_num_rows($result); PHP:
Slightly different problem now $sql = "SELECT * FROM " . ADR_LIBRARY_TABLE ." WHERE book_difficulty <= $book_difficulty AND book_zone = $area_id"; $result = $db->sql_query($sql); if( !$result ) { message_die(GENERAL_ERROR, 'Could not obtain book information', "", __LINE__, __FILE__, $sql); } $books = mysql_num_rows($result); $library = $db->sql_fetchrow($result); } if ( !$library ) { adr_previous ( Adr_library_failure , adr_research , '' ); } else { // Now roll for research $rnd_research = mt_rand ( 1 , $books); $sql = "SELECT * FROM " . ADR_LIBRARY_TABLE ." WHERE book_id = '".$library[$rnd_research]['book_id']."' "; $result = $db->sql_query($sql); if( !$result ) { message_die(GENERAL_ERROR, 'Could not obtain book information', "", __LINE__, __FILE__, $sql); } $research_result = $db->sql_fetchrow($result); PHP: The above code is supposed to get all possible results for a MySQL query and store them as $library. Then, a random result is called from this list, and all it's information retrieved from the database. The first query works, the second doesn't.
No errors. By echo statements, I've found that $library[$rnd_research]['book_id'] has no value. It's supposed to get a random row from $library, as determined by $rnd_research. However, it doesn't. $library['book_id'] has a value, but always the same one.
Found what was wrong This $library = $db->sql_fetchrow($result); PHP: should have been $library = $db->sql_fetchrowset($result); PHP: