Created Comma Seperated List from MySQL DB





6
Date Submitted Thu. Mar. 1st, 2007 3:45 PM
Revision 1 of 1
Helper mjlintz
Tags PHP
Comments 1 comments
Pull items from a mysql db table and display in the following format-
item1, item2, item3

In the example code, the query will return all items that have the color "red" specified in the db.

<?
$query = mysql_query("SELECT item FROM table WHERE color = 'red'");

$system_array = array() ;
$i = 0 ;
while ( $row = mysql_fetch_assoc( $query ) )
{
   $system_array[ $i ] = $row[ 'item' ] ;
   $i++ ;
}
$item_list =  implode( ', ', $system_array ) ;
echo $item_list;
?>
 

Michael Lintz

Comments

Comments Array keys
Thu. Mar. 1st, 2007 4:26 PM    Helper Nico

Voting