selecting no and data of results from the same function, how

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

selecting no and data of results from the same function, how

Post by PHPycho »

i am using one function for fetching the data from mysql and another for fetching the no of data, but what i want to do is i want to return the no of data and data results from the one function only.
i am using two functions as:
-for fetching data

Code: Select all

function selectAll()
	{
		global $ado;
		$sql = "SELECT * FROM `category`";
		return $ado->exec($sql);
 	}
-for fetching no of data

Code: Select all

function selectNo()
	{
		global $ado;
		$sql = "SELECT * FROM `category`";
		$result = $ado->exec($sql);
                return $ado->row_count($result);
 	}
above method is abviously tedious and non logical.
I want to do two action in one function, Please guide me.
Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe something like

Code: Select all

function select() {
	global $ado;
	$sql = "SELECT * FROM `category`";
  $result = $ado->exec($sql);
	return array('count'=>$ado->row_count($result), 'result'=>$result);
}
btw: I find "no of data" confusing. row count, record count, number of records ...much easier.
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

Pardon me.
i mean no of data to be no of rows.
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

thanks mr. volka , hats off to you
thats the perfect solution i was searching for. it just rocked.
Post Reply