I have this PHP code:
if ($username) {
if ($news == 1)
$int = "9";
if ($news == 0)
$int = "12";
}
else
$int = "9";
$query = mysql_query("SELECT * FROM files WHERE active='1' ORDER BY id DESC LIMIT $int");
require ("scripts/connect.php");
$numrows = mysql_num_rows($query);
But then I get this error (Note the line starting with $numrows is line 69):
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/Site/index.php on line 69
I have tried many ways of changing the number to no avail. Please help! Thanks!
If your
scripts/connect.phpis responsible for establishing database connection, then I belivemysql_query()should be below it, not above as it is now. I also recommend usingmysql_error()and always check return values for errors, as assumptions like “query is always successful” are no-no approach and will hit you badly in less expected moment.Please note
mysqlextension is deprecated. Switch tomysqlior something more sophisticated likePDOas soon as you can.