Jump to content

[SOLVED] SQL_CALC_FOUND_ROWS


The Little Guy

Recommended Posts

OK, I am not getting my FOUND_ROWS() function to work in the following code:

$_id = 1;
$limit = 0;
$max = 8;
$sql = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM images WHERE owner = '$_id' ORDER by id DESC LIMIT $limit, $max")or die(mysql_error());
$result_count = mysql_query("SELECT FOUND_ROWS()")or die(mysql_error());
$total = mysql_fetch_array($result_count);
$totalrows = $total[0];
echo $totalrows;

 

If I were to remove the LIMIT, I would get 12 results, but $totalrows echo's out 0. What could have happened for this not to work, or am I missing something?

 

This used to work before, but now it doesn't work, and I don't know why...

Link to comment
https://forums.phpfreaks.com/topic/168750-solved-sql_calc_found_rows/
Share on other sites

try

 

$_id = 1;
$limit = 0;
$max = 8;
$sql = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM images WHERE owner = '$_id' ORDER by id DESC LIMIT $limit, $max")or die(mysql_error());
$result_count = mysql_query("SELECT FOUND_ROWS() as `found_rows`")or die(mysql_error());
$total = mysql_fetch_array($result_count);
$totalrows = $total['found_rows'];
echo $totalrows;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.