| captainmerton |
07-14-2009 07:42 PM |
Returning an array from a function
I want to create a function that goes away and collects data from a database that will be used in a form drop down. I assume the best way to do this is an array as the number of rows of data returned will vary. Essentially i want to build an array as i read th rows then return the array from the function. How do I go about doing this and how do I handle the data when calling the function. the code I have inside the function (PS i havent included all the function code just the main part of it):
PHP Code:
function getList($data1,$data2) {
$query = ("SELECT blahdata from blahtable
WHERE blahcolumn == "$data1");
$result = mysql_query($query) OR die("Cannot perform getList query!");
if (mysql_num_rows($result) == 0) {
return 0;
} else {
$arr=array();
$counter=0;
while($row = mysql_fetch_array($result))
{
$arr[$counter]=$row['blahdata'];
$counter=$counter+1;
}
return $arr;
}
}
I find if I call the function using a print statement I get "0" when there is no rows as expected but "array" when there ares rows. Do i need to explode the array?
|