Hi, I programmed a database query some months ago and then had to go offline for a while. Now I find that I left the project unfinished with some bug that I can't see right now. Here's the code: $_query = sprintf("SELECT SQL_CALC_FOUND_ROWS id, title, text FROM articles WHERE status = 'approved' ORDER BY id LIMIT %d,%d", SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit() ); $_result = mysql_query($_query); while ($_row = mysql_fetch_array($_result, MYSQL_ASSOC)) { // collect each record into $_data $_data[] = $_row; } PHP: The error message is: It points to the first line of the while loop. I know the data is there, so $_row is not an empty result, I think. Any help, please?
Typically you get that error when the query did not return a resource, normally because it failed or there were no rows. Try: echo mysql_num_rows($_result); and see if the query is returning any rows.
Yes this problem generraly generated in case of no data..... Try with some condition . In case of true mysql_fetch_array executed otherwise do nothing
It does not occur because there is no data. Most probably the query returned an error. Change the query line to $_result = mysql_query($_query) or die("MySQL error - ".mysql_errno()." - ".mysql_error()); PHP: To see if the query you constructed is valid, just do an echo of $query.