...

View Full Version : Resolved Help returning values from a function?



stfc_boy
08-24-2011, 03:51 PM
Hi,

I'm looking for some help please to write a function, which:

1) Queries a database
2) Could return ONE or MORE results
3) Return either the ONE or MORE results comma seperated

However, I can only get this to return one value, how would I get it to return multiple values?



function findName($name) {
$sql = "select id from table WHERE name LIKE '%$name%'";
$query = mysql_query($sql);
while($result = mysql_fetch_array($query) {
$the_ids = $result['id'];
}
return $the_ids;
}


So the above could return multiple ids eg:

1,56,86,72

Or simply just a single id eg:

56

Can this be done and can anyone kindly help please?

Thanks

abduraooft
08-24-2011, 04:07 PM
function findName($name) {
$sql = "select id from table WHERE name LIKE '%$name%'";
$query = mysql_query($sql);
while($result = mysql_fetch_array($query) {
$the_ids[] = $result['id'];
}
return $the_ids;
}


$names=findName('some value');

if(is_array($names))
echo $names=implode(',',$names );



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum