Results 1 to 4 of 4

Thread: need help cleaning up fetchall from mysql database

  1. #1
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default need help cleaning up fetchall from mysql database

    I have the following php code:

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

                
    $sth $connect->prepare("SELECT email FROM contacts");
                
    $sth->execute();
                
    $result $sth->fetchAll(PDO::FETCH_COLUMN0);
                
            
    $v var_export($resulttrue);
          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
    Last edited by james438; 09-17-2014 at 02:47 PM.

  2. #2
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    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

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    If I am understanding you correctly just replace

    Code:
            $v = var_export($result, true);
    with
    Code:
            $v = implode(", ", $result);
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    May 2009
    Location
    Greensboro, GA
    Posts
    163
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    It was that easy. Thanks

Similar Threads

  1. MySQL Database
    By lawrencee99 in forum MySQL and other databases
    Replies: 7
    Last Post: 03-14-2014, 02:16 AM
  2. Replies: 1
    Last Post: 10-20-2010, 06:18 AM
  3. mySQL database help!!??!!
    By nikomou in forum PHP
    Replies: 7
    Last Post: 11-21-2007, 04:25 PM
  4. Cleaning up my code.. a little advice?
    By BLiZZaRD in forum PHP
    Replies: 15
    Last Post: 11-20-2007, 01:43 PM
  5. Cleaning Up A String
    By Titan85 in forum PHP
    Replies: 2
    Last Post: 07-02-2007, 04:52 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •