#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0

    Help with array from DB table


    I am new to PHP and I may simply be overlooking something but i have the following code:

    <?php
    $query = "SELECT *
    FROM orgchart
    ORDER BY name ASC";
    $content_set = mysql_query($query, $connection);

    $content = mysql_fetch_array($content_set);
    print_r($content);
    ?>

    When i do the print_r i get this:

    Array ( [0] => 8 [id] => 8 [1] => recruit [name] => recruit [2] => recruit [title] => recruit [3] => krisemp1 [supername] => krisemp1 )

    which is a very jumbled version of what is in my database across multiple columns and rows.

    Any advice on getting a clean array into my $content?
    Or at least tell me what in the world its pulling?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,921
    Rep Power
    1045
    Hi,

    Originally Posted by kirklogan
    Or at least tell me what in the world its pulling?
    It's pulling the first row of the result set as an array with both numeric and string indices -- just like you told it to do.

    If you only want string indices, you have to pass MYSQL_ASSOC as the second parameter or instead use mysql_fetch_assoc().

    By the way, using "SELECT *" is bad style, because you have no control over what it's actually selecting. Select specific columns.

IMN logo majestic logo threadwatch logo seochat tools logo