Welcome Guest, Not a member yet? Register   Sign In
Help needed with Array.
#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.


Messages In This Thread
Help needed with Array. - by El Forum - 01-17-2009, 11:30 AM
Help needed with Array. - by El Forum - 01-17-2009, 12:17 PM
Help needed with Array. - by El Forum - 01-17-2009, 12:25 PM
Help needed with Array. - by El Forum - 01-18-2009, 01:12 PM
Help needed with Array. - by El Forum - 01-18-2009, 02:28 PM
Help needed with Array. - by El Forum - 01-18-2009, 04:25 PM
Help needed with Array. - by El Forum - 01-18-2009, 07:02 PM
Help needed with Array. - by El Forum - 03-11-2009, 09:28 PM
Help needed with Array. - by El Forum - 03-11-2009, 09:32 PM
Help needed with Array. - by El Forum - 03-11-2009, 09:55 PM
Help needed with Array. - by El Forum - 03-11-2009, 09:58 PM
Help needed with Array. - by El Forum - 03-11-2009, 10:02 PM
Help needed with Array. - by El Forum - 03-11-2009, 10:06 PM
Help needed with Array. - by El Forum - 03-12-2009, 06:17 AM
Help needed with Array. - by El Forum - 03-12-2009, 07:03 AM
Help needed with Array. - by El Forum - 03-12-2009, 07:39 AM
Help needed with Array. - by El Forum - 03-12-2009, 07:51 AM
Help needed with Array. - by El Forum - 03-12-2009, 08:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB