Jump to content

How do i use return to output more than one row of information?


newb

Recommended Posts

How can i use return to output more than one row of information? i would like to merge the results from multiple SQL rows into one string somehow so that I can return them through a function. Any ideas how i can do this? here is my current code:

	$query = exec_mysql_query("SELECT * FROM av_genres WHERE id = $cid ORDER BY name DESC");
	while ($row = mysql_fetch_assoc($query)) {
		return $row['name'];
	}

 

if i use 'echo' it displays all results as i want it to but it doesnt output in the correct place for some reason. any ideas?

 

You can only return one value.  If you want the results as a string, have the function build that string through concatenation and then return it.  You could also store each result in an array and return the array.

 

$ret = '';
$query = exec_mysql_query("SELECT * FROM av_genres WHERE id = $cid ORDER BY name DESC");
while ($row = mysql_fetch_assoc($query)) {
$ret .= $row['name'].', ';
}
return $ret;

if i use 'echo' it displays all results as i want it to but it doesnt output in the correct place for some reason. any ideas?

 

What do you mean by that? For example, you want it a certain spot on a web page?

You can only return one value.  If you want the results as a string, have the function build that string through concatenation and then return it.  You could also store each result in an array and return the array.

 

$ret = '';
$query = exec_mysql_query("SELECT * FROM av_genres WHERE id = $cid ORDER BY name DESC");
while ($row = mysql_fetch_assoc($query)) {
$ret .= $row['name'].', ';
}
return $ret;

 

exactly what i needed, thanks.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.