I need to use the mysql query result.following is the mysql query.

while($row = mysql_fetch_array($result))


For example: result of above query is (name1,name2,name3...)

The problem is...
i need to return that result in the following function.How can i do it?

function results()

return array(
    'name1' => t('name1'),
    'name2' => t('name2'),
    'name3' => t('name3'),


plz anyone help me.

First if I understand good, as a result you want to return ALL the names from the query.

If that is the case, in this first while loop, instead of using $name = $row;,use:

$names = array();

while($row = mysql_fetch_array($result))

This code will push the names from the query automatically to the array called $names.
And for example after 3 runs through the for loop, $name array would look like this:

$names = array([0] => "name1", [1] => "name2", [2] => "name3");

Of course for example to retrieve first name from the list you would type:

echo $names[0];

And returning the entire array with names now through the function is easy:

function returnNames()
       return $this->names;

this would return to you the array with all the names from the query in one array.

Hope I helped you a bit with this,

Best regards,


Thanks a Lot.It helps me.