Results 1 to 3 of 3

Thread: [RESOLVED] Array instead of " "

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Array instead of " "

    Hi,

    I am using this code to display data to the screen:

    PHP Code:
     mysql_connect($db_host,$db_user,$db_pass);
    mysql_select_db($db_name) or die("Unable to select database.");
                  
    $data mysql_query("SELECT * FROM $table");

                while(
    $info mysql_fetch_array$data,MYSQL_NUM )){
         
                 
    $comma_separated implode("",  $info);
                 echo 
    $comma_separated;
              
    $comma_separated explode(" ",  $comma_separated);
     echo 
    $comma_separated;
                 } 
    However, for some reason instead of putting a " " between entries it puts

    Array
    1Jeff13Male12/04/84Array2Mike17Male05/06/1990Array3Joann17Female26/06/1982Array4Rachel14Female23/07/1980Array5Robert13Male23/06/1990Array6Sarah14Female21/4/1990Array7evaneeeArray8fionafffArray
    Thanks,

    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Array instead of " "

    you should probably read exactly what explode() and implode() do.

    implode() will take an array and turn it into a string with a string in between each item.

    explode() will take a string and turn it into an array by splitting it at every string.

    it outputs the second quote the way it is because:
    • you're using implode() to turn an array into a string with nothing in between each item.
    • you're using explode() to turn a string created by implode() into an array (delimited by spaces, of which none exist in your string), and then you're echoing out that array. it's an array and obviously won't print anything; use print_r() to print arrays. it will still only print an array with a long string as the first and only value, though..


    so yeah. use implode() with a comma or space as the string parameter and $info as the array, then echo that. don't use explode(). look at PHP.net if you don't understand how a function works.

    edit: and, you may want to take a look at the last post I added in the last thread you made (about mysql_fetch_array()). you can use mysql_fetch_num() or mysql_fetch_assoc() instead if you'd prefer; it's much easier to read.
    Last edited by kows; Jan 1st, 2010 at 01:37 AM.

  3. #3

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Array instead of " "

    I used:

    PHP Code:
    $comma_separated implode(",",  $info); 
    and removed:

    PHP Code:
    $comma_separated explode(" ",  $comma_separated); 
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

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



Click Here to Expand Forum to Full Width