Log in

View Full Version : Resolved need help cleaning up fetchall from mysql database



mcolton
09-13-2014, 12:01 PM
I have the following php code:



$connect = new PDO('mysql:host=localhost;dbname=xxxxx', "xxxx", "xxxx");
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sth = $connect->prepare("SELECT email FROM contacts");
$sth->execute();
$result = $sth->fetchAll(PDO::FETCH_COLUMN, 0);

$v = var_export($result, true);
echo $v;


The partial results look like this:

array ( 0 => 'martyc@windstream.net', 1 => 'emailaddress2', 2 => 'emailaddress3', 3 => 'emailaddress4', 4 =>

How can I get this to look like this:
martyc@windstream.net, emailaddress2, emailaddress3, emailaddress4,

Thanks for any help

mcolton
09-16-2014, 11:55 AM
Is there no one who could tell me how to get 1 column from a database without the extra stuff like row number and "=>".
I've been working on this for weeks

james438
09-17-2014, 05:20 AM
If I am understanding you correctly just replace


$v = var_export($result, true);
with

$v = implode(", ", $result);

mcolton
09-17-2014, 01:24 PM
It was that easy. Thanks