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?

 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.