Page 1 of 1

[PHP-Simple] Comma Seperated Implode of SQL Data

Posted: Fri Jul 23, 2010 1:14 pm
by bla5e
Ive done it before but cannot remember how to do it..
code im using so far only returns the last record

Code: Select all

$query = "SELECT productid FROM templates_products_associated WHERE templateid={$req_vars['id']}";
$sql = pg_query($db,$query);
$pub = pg_fetch_assoc($sql);
$pubs = implode(',',$pub);
print_r($pubs);
Trying to get all the productids, seperate by commas

Re: [PHP-Simple] Comma Seperated Implode of SQL Data

Posted: Fri Jul 23, 2010 1:54 pm
by AbraCadaver

Code: Select all

while($row = pg_fetch_assoc($sql)) {
   $pubs[] = $row['productid'];
}
$pubs = implode(',', $pubs);
print_r($pubs);