The mysql fetch results are empty if I retrieve all rows
I'm having some issues returning values from a server with php + mysql.
This is my code
$result = mysql_query("SELECT * FROM Nicknames", $con);
if (mysql_real_escape_string($_POST['Create']) == "NICKNAME") {
$output;
while ($row = mysql_fetch_assoc($result)) {
if ($row['Taken'] == '0') $output = $output . $row['Nickname'] . ",";
}
echo substr($output, 0, -1);
}
If I add break; in the while loop, it works perfectly and I just get 1 row of my table. If instead I want to return all 3000 rows, I just get an empty answer from the server.
If the table has 10 rows it works.
I was wondering if it is about the amount of rows, or it is because eventual special characters.
thanks
UPDATE It works until 1330 rows, if I try to get more, I get an empty result
$counter = 0;
while ($row = mysql_fetch_assoc($result)) {
if ($row['Taken'] == '0') $output = $output . $row['Nickname'] . ",";
if ($counter == 1330) break;
$counter++;
开发者_Go百科 }
echo substr($output, 0, -1);
Somewhere in the middle of your table's rows there may have been an invalid character.
Since you know which row it stops working at, try running the SELECT with different ORDER BY's to determine if this is the case. :)
Have you tried showing error messages?
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', true);
It is possible that $output is filling the memory_limit before getting to your echo, and if display_errors is false, you won't see the error stating out of memory.
Maybe it's too obvious, but ... Have you checked the max_execution_time value in your php.ini ?
Maybe the script is dying before finishing the 3000 rows fetch.
Try setting
set_time_limit(0);
at the beginning of the script to avoid this problem
$output
after the if condition should be $output = "";
精彩评论