In my website I changed this:
$genre_result = mysql_query
(
" SELECT g.genre_id, g.genre_name
FROM genres as g;"
);
$game_result = mysql_query
(
" SELECT g.genre_id, g.game_id, g.game_name
FROM games as g;"
);
$genre_array = array();
$game_array = array();
while ($genre_row = mysql_fetch_row($genre_result))
{
$genre_index = $genre_row[0] - 1;
$genre_array[$genre_index] = $genre_row[1];
$game_array[$genre_index] = array();
$game_array[$genre_index][] = array();
$game_array[$genre_index][] = array();
}
while ($game_row = mysql_fetch_row($game_result))
{
$genre_index = $game_row[0] - 1;
$game_array[$genre_index][0][] = $game_row[1];
$game_array[$genre_index][1][] = $game_row[2];
}
to this (I copied the SELECT blocks into two new procedures):
$genre_result = mysql_query
(
"CALL get_genres();"
);
$game_result = mysql_query
(
"CALL get_games();"
);
$genre_array = array();
$game_array = array();
while ($genre_row = mysql_fetch_row($genre_result))
{
$genre_index = $genre_row[0] - 1;
$genre_array[$genre_index] = $genre_row[1];
$game_array[$genre_index] = array();
$game_array[$genre_index][] = array();
$game_array[$genre_index][] = array();
}
while ($game_row = mysql_fetch_row($game_result)) // line #61
{
$genre_index = $game_row[0] - 1;
$game_array[$genre_index][0][] = $game_row[1];
$game_array[$genre_index][1][] = $game_row[2];
}
Now I get a PHP error for line #61 (which I have marked in the above code):
Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /home2/isometr1/public_html/keyboard/keyboard.php on line 61
The get_genres() and get_games() procedures work properly in phpmyadmin, returning the proper values. What did I do wrong so that my code doesn't work?
Also, phpmyadmin issues this complaint, though I don't know if it's related:
You are using PHP's deprecated 'mysql' extension, which is not capable of handling multi queries. The execution of some stored routines may fail! Please use the improved 'mysqli' extension to avoid any problems.
[edit 1]
I tried mysql_error() like this:
$genre_result = mysql_query("CALL get_genres();", $con);
echo mysql_errno($con) . ": " . mysql_error($con) . "\n";
$game_result = mysql_query("CALL get_games();", $con);
echo mysql_errno($con) . ": " . mysql_error($con) . "\n";
And got this error:
0: 2014: Commands out of sync; you can't run this command now
Here are my version numbers:
MySQL version 5.1.70-cll
phpMyAdmin version 3.5.8
cpanel version 11
PHP version 5.3.22
[edit 2]
Based on GolezTrol's suggestions I also tried this with no improvement:
// genres & games
$genre_array = array();
$game_array = array();
$genre_result = mysql_query("CALL get_genres();", $con);
while ($genre_row = mysql_fetch_row($genre_result))
{
$genre_index = $genre_row[0] - 1;
$genre_array[$genre_index] = $genre_row[1];
$game_array[$genre_index] = array();
$game_array[$genre_index][] = array();
$game_array[$genre_index][] = array();
}
$game_result = mysql_query("CALL get_games();", $con);
while ($game_row = mysql_fetch_row($game_result))
{
$genre_index = $game_row[0] - 1;
$game_array[$genre_index][0][] = $game_row[1];
$game_array[$genre_index][1][] = $game_row[2];
}