Page 1 of 1

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

Posted: Mon Jan 15, 2007 10:41 pm
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

Posted: Mon Jan 15, 2007 10:52 pm
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.

Posted: Mon Jan 15, 2007 11:11 pm
by PHPycho
Pardon me.
i mean no of data to be no of rows.

Posted: Tue Jan 16, 2007 12:25 am
by PHPycho
thanks mr. volka , hats off to you
thats the perfect solution i was searching for. it just rocked.