Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array displays with weird duplicates

    Hi, i am trying to sort out the arrays for a section of my website, at the moment i am trying to just get them to setup properly before i start using them. The problem i have is that i ouputed them but for some reason they show up as duplicates, is this right? or how do i get rid of the duplicates?

    This is what gets displayed on screen

    Code:
    Column name: 0 Column data: default
    Column name: ext_token Column data: default
    Column name: 1 Column data: default
    Column name: ext_token_child Column data: default
    Column name: 2 Column data: 4
    Column name: concrete Column data: 4
    Column name: 3 Column data: 3
    Column name: cement Column data: 3
    Column name: 4 Column data: 2
    Column name: sand Column data: 2
    Column name: 15 Column data: 4
    Column name: wood_4_2 Column data: 4
    Column name: 16 Column data: 2
    Column name: wood_8_2 Column data: 2
    I want to get rid of all the elements with numbers as the column name

    And this is the code

    PHP Code:
    $result mysql_query("SELECT * FROM extension_material_required WHERE ext_token = 'default' AND ext_token_child = 'default'"$conn2) or die(mysql_error());
    $result_array mysql_fetch_array($result);
    $new_result_array array_filter($result_array'strlen');
    foreach (
    $new_result_array as $columnName => $columnData) {
            echo 
    'Column name: ' $columnName ' Column data: ' $columnData '<br />';
        } 
    Thanks for any and all help

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    mysql_fetch_array() returns both numeric and associative indexes so yes the data is effectively doubled instead use
    PHP Code:
    $result_array mysql_fetch_assoc($result)
    //or
    $result_array mysql_fetch_row($result
    mysql_fetch_assoc() is normally easier to work with which will return $result_array['first_fieldname'] rather than $result_array[0] etc
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Tags for this Thread

    Posting Permissions

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