Hi,

I'm trying to display the results from a query in a comma delimmited string. My thought was to use the mysql_fetch_array function to load all of the data into an arry. Afterwards, I thought I'd use the implode function to take the contents of the array and compress it into a comma delimited string, which I would display in a column:

[INDENT]$query = "SELECT name
from profiles_xref, profiles
WHERE profiles.profile_id = profiles_xref.profile_id AND
profiles_xref.issue_id = $id AND
profiles_xref.role = '$role_code'
";

$result = mysql_query($query) or die('Could not profiles with '. $role );
while($row = mysql_fetch_array($result, MYSQL_NUM)) {
}
$character=implode(",", $result);
echo "$Value: $character</br>\n";[/INDENT]

However, I receive the following error message:
Warning: implode() [function.implode]: Bad arguments. in C:\wamp\listing.inc.php on line 37

I've looked at information in the PHP manual at http://www.php.net/manual/en, but I haven't been able to piece together what I am doing wrong.

Can anyone tell me how to use implode with character data fetched into an array?

Thanks

    My thought was to use the mysql_fetch_array function to load all of the data into an arry

    The problem is that you forgot to load the names into an array.

    $query = "SELECT name
    from profiles_xref, profiles
    WHERE profiles.profile_id = profiles_xref.profile_id AND
    profiles_xref.issue_id = $id AND
    profiles_xref.role = '$role_code'
    ";
    
    $result = mysql_query($query) or die('Could not profiles with '. $role );
    $names = array();
    while($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $names[] = $row['name'];
    }
    $character = implode(",", $names);
    echo "$Value: $character</br>\n";

      That makes perfect sense... now that I see your reply. I mistankely thought that the data was dumped into the result array, which I could implode into another array.

      Thanks

      -CHL3

        Write a Reply...