Welcome Guest, Not a member yet? Register   Sign In
Help needed with Array.
#11

[eluser]TheFuzzy0ne[/eluser]
Not unless you're going to post some more code. The error refers to a "contacts_array", which I see no mention of in your code.
#12

[eluser]gscharlemann[/eluser]
The "contacts_array" is a copy and paste error. I renamed the array to people_array.

Any idea what the "$msg_name not passedArray" means at the beginning of the array dump? - nevermind... i see it in the function parameter.
#13

[eluser]TheFuzzy0ne[/eluser]
No idea whatsoever... Could it be part of another error, or a debug statement?

Please repost you code as it is now, along with the error again. (I get confused easily).
#14

[eluser]gscharlemann[/eluser]
I tried a new angle and created the following array in the controller:
Code:
$person_1 = array();
$person_2 = array();
$person_1['contact_number'] = 1;
$person_1['first_name'] = "John";
$person_1['last_name'] = "Doe";
$person_2['contact_number'] = 2;
$person_2['first_name'] = "Jane";
$person_2['last_name'] = "Doe";
$people_array = array();
$people_array[0] = $person_1;
$people_array[1] = $person_2;

I verify the contents of the array using the fred() function provided earlier in this thread. The result is:
Code:
$msg_name not passedArray
(
    [0] => Array
        (
            [contact_number] => 1
            [first_name] => John
            [last_name] => Doe
        )

    [1] => Array
        (
            [contact_number] => 2
            [first_name] => Jane
            [last_name] => Doe
        )

)

I then make a call to load the view and try to pass $people_array:
Code:
$this->load->view('contact/display_people', $people_array);

I don't do anything special in the view (should I?). The first php call I make is the foreach statement below:
Code:
<?php foreach($people_array as $person): ?>
    <tr>
        <td>&lt;?php echo $person['contact_id'];?&gt;</td>
        <td>&lt;?php echo $person['first_name'];?&gt;</td>
        <td>&lt;?php echo $person['last_name'];?&gt;</td>
    </tr>
&lt;?php endforeach;?&gt;

Is there something that I'm not doing in the view that I should be doing? Do I need to define what parameters can be passed to it? Or if I wanted to pass an additional variable to the view, would it simply be modifying the call to load the view, for example:
Code:
$this->load->view('contact/display_people', $people_array, $test_var);

Thanks again for all your help.
#15

[eluser]TheFuzzy0ne[/eluser]
Ah-ha! The people array doesn't exist in the scope of the view. You need to insert it like this (from your controller:
Code:
$data['people_array'] = $people_array; # <- The key on the data array is what's used as the variable name in the view.
$this->load->view('contact/display_people, $data);

Passing in that third parameter won't do you any justice there either, as that third parameter should either be TRUE or FALSE, and specified whether or not the content ot the loaded view should be returned for storing in a variable, or output straight to the browser.

Sorry I didn't spot this before. It was far too early in the morning. (I think it was about 5AM) and I hadn't gone to bed yet.
#16

[eluser]gscharlemann[/eluser]
No apologies necessary. I'll have to give that a shot when I get home from work to see how it works. Sounds like you figured it out. Thank you!
#17

[eluser]TheFuzzy0ne[/eluser]
And as for the "$msg_name not passed". You can just pass a description/message into fred() as the second parameter.

I didn't notice that function before. I thought you were just doing a var_dump.
#18

[eluser]gscharlemann[/eluser]
Code:
$data['people_array'] = $people_array;

That did it. Thanks again for your help!




Theme © iAndrew 2016 - Forum software by © MyBB