One possible solution could be to write a simple class that will hold all data you need at one single place:
class MyData { var $_resultArray; var $_rows; var $_fields;
function MyData($resultArray, $rows, $fields) { $this->data = $data; $this->rowcounr = $rowcount; $this->fildcount = $fildcount; }
function getResultArray() { return $this->_resultArray; }
function getRows() { return $this->_rows; }
function getFilds () { return $this->_fields; } }
To put some data in that object write:
$data = new MyData($theResultArray, $rows, $fields);
To get back your stuff in your code use something like:
$theResultArray = MyData->getResultArray(); $rows = MyData->getRows(); $fields = MyData->getFields();
This is only an example code, you should adjust it according your needs
hth
Boyan --
Chris W. Parker wrote:
Hi list.
Ok I know it's not possible to "return" more than one value. But I'm going to explain what I'd like to do so maybe there's an easy way to do it.
I've got some functions that query a database and turn the result into an array and return that array. What I'd like to do is not only return the array of results but ALSO return a row count and field count of that result.
Here is some pseudo code:
function get_results() { // query database $result = query($sql); // turn result set into a useable array $theResultArray = get_results($result);
$rows = mysql_num_rows($result); $fields = mysql_num_fields($result);
return $theResultArray; return $rows; return $fields; }
Ok I know that won't work but that's just basically what I want to do.
The only way around this I've come up with is to stick all the values into ANOTHER array and return then and then dissect that array in the calling function, but that just seems messy.
All of a sudden the word "reference" came to mind. Is that what I want to use?
Any help would be appreciated.
Thanks, Chris. -- Don't like reformatting your Outlook replies? Now there's relief! http://home.in.tum.de/~jain/software/outlook-quotefix/
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php