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 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2013
    Location
    Finland/Estonia
    Posts
    53
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Needing some help with reading query results from Array

    Hello. I am currently creating a system that'd favor using query results outside the query. So I read up and found out that Arrays are the way to go. However, I have no experience with arrays.
    This is how the PHP/MYSQL Snippet looks like:
    PHP Code:
    $settings_results = array();
    $sql_settings "SELECT * FROM config";
    if (
    $result $db->query($sql_settings)){
        while(
    $row $result->fetch_assoc()){
          
    $settings_results[] = $row;
        }
    }
    //debugging
    print_r($settings_results); 
    This takes care of fetching the results from the database and storing them in an array. However, the array shows up complicated for a rookie like me. It seems to create arrays inside arrays.
    Code:
    Array ( [0] => Array ( [config_id] => 1 [setting_1] => Data ) [1] => Array ( [config_id] => 2 [setting_1] => true ) [2] => Array ( [config_id] => 3 [setting_1] => ) )
    What I want to end up with is, the first result (Data in this case) is 0 in the array, the true is 1 etc, so I could refer to them with $settings_results[0] etc..
    Last edited by estXcrew; 11-29-2013 at 10:25 PM.

  • #2
    New Coder
    Join Date
    Nov 2011
    Location
    Ratio, Logic
    Posts
    60
    Thanks
    3
    Thanked 6 Times in 6 Posts
    As printed, single results are as follows
    PHP Code:
    $settings_results[0]['setting_1'] = 'Data';
    $settings_results[1]['setting_1'] = true;
    $settings_results[2]['setting_1'] = '';

    $settings_results[2]['config_id'] = 3
    It is called multidimensional array when are set array(s) in array.

    In square brackets are indexes of initialized array (in this case $settings_results).
    Arrays.

  • Users who have thanked Tpojka for this post:

    estXcrew (11-29-2013)

  • #3
    New Coder
    Join Date
    Jul 2013
    Location
    Finland/Estonia
    Posts
    53
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Tpojka View Post
    As printed, single results are as follows
    PHP Code:
    $settings_results[0]['setting_1'] = 'Data';
    $settings_results[1]['setting_1'] = true;
    $settings_results[2]['setting_1'] = '';

    $settings_results[2]['config_id'] = 3
    It is called multidimensional array when are set array(s) in array.

    In square brackets are indexes of initialized array (in this case $settings_results).
    Arrays.
    Thank you. I'm going to try it out right now. I did read the php.net article but it didn't get to me.

    -->Edit<--

    Thanks mate. It worked.
    Last edited by estXcrew; 11-29-2013 at 09:59 PM.


  •  

    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
    •