DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Michael has posted 27 posts at DZone. View Full User Profile

Created Comma Seperated List From DB

01.09.2007
| 108 views |
  • submit to reddit
        // The following returns a comma seperated list of values from mysql db
// Example: Item1, Item2, Item3

$query = mysql_query("SELECT b.system_name FROM csr_assigned_system a, csr_system b WHERE a.csr_id = '$csr_id' AND b.system_id = a.system_id"); 

$system_array = array() ; 
$i = 0 ; 
while ( $row = mysql_fetch_assoc( $query ) ) 
{ 
   $system_array[ $i ] = $row[ 'system_name' ] ; 
   $i++ ; 
} 
$system =  implode( ', ', $system_array ) ;
echo $system;