Novell is now a part of Micro Focus

I'm having trouble getting SQL_CALC_FOUND_ROWS from PHP. When...

Articles and Tips: qna

01 May 2003


Q.

I'm having trouble getting SQL_CALC_FOUND_ROWS from PHP. When I run the following code, the result (in $count_result) is "Resource id #4," not the number of rows.

$sql = "Select SQL_CALC_FOUND_ROWS 'field1',
			'field2' FROM 'table' WHERE
	'this'='that' LIMIT 50";
	$result = mysql_query($strSQL);
$sql = "Select FOUND_ROWS()";
	$count_result = mysql_query($strSQL);

A.

Try it like this:

$sql = "Select SQL_CALC_FOUND_ROWS 'field1',
			'field2' FROM 'table' WHERE 
	'this'='that' LIMIT 50";
	$result = mysql_query($strSQL);
$count_result = mysql_query("Select
			FOUND_ROWS()");
	$total_rows = ($count_result > 0) ?
			mysql_result($count_result, 0, 0) : 0;

* Originally published in Novell AppNotes


Disclaimer

The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.

© Copyright Micro Focus or one of its affiliates