Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning a number from a count

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hi all, I have some code in PHP that is used to count the number of rows returned from a MySQL query. here is the function
Code:
function list_apps($start = null, $per_page = null)
	{
		$connection = db_connect();
		$query =	"	SELECT	*
						FROM		coll_downloads
						WHERE		dlapp = '1'
						";
	
$result = mysql_query($query);
	
	//counts the number of rows in the query
	[COLOR=red]$number_of_posts = mysql_num_rows($result);[/color]
	if($number_of_posts == 0)
	{
		return false;	
	}
	
	if(isset($start)&& isset($per_page))
	{
		$query .=" LIMIT $start, $per_page";	
	}
	$result = mysql_query($query);
	
	//changes the result into an array using the result_to_array function
	$result = result_to_array($result);
	return array('result'=> $result, 'num_events'=> $number_of_posts);
}
the $number_of_posts should (at least I thought it should) return a number of rows from the query. I've tried echoing this out on the page but nothing shows.

I've read quite a few posts in this forum about the code to count the rows but very few of them tell you how to display the result.

Any help would be appreciated

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Sorry, been jumping between the two forums, didn't realise which one I was in....

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
PHP forum is here forum434


But as a starter I would start debugging the mysql calls, by attaching or die(mysql_error()); to the calls.

mysql_num_rows should in fact return the number of rows generated by the query.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top