Welcome Guest, Not a member yet? Register   Sign In
Stuffing array into active record insert
#1

[eluser]stevefink[/eluser]
Hi all,

I was just curious, is there a reason an Array with multiple elements is not properly being inserted using $this->db->insert with the Active Record class? Here's what my Array looks like:

Code:
DEBUG - 2007-11-05 11:20:32 --> testing for $p: Array
(
    [0] => Array
        (
            [first_name] => Steve
        )

    [1] => Array
        (
            [middle_initial] => S
        )

    [2] => Array
        (
            [last_name] => Finkelstein
        )

    [3] => Array
        (
            [room_number] => 301
        )

    [4] => Array
        (
            [cpt_id] => 1
        )

)

And my PHP:

Code:
function insert_patient($p) {
        log_message('debug', "testing for \$p: ".print_r($p, TRUE));
        $this->db->insert('ms_patients', $p);
    }

Thanks for any hints.. :-)
#2

[eluser]gtech[/eluser]
I would set $p to the following and see if that works (thats how I use the insert and it works for me).
Code:
...
$p = array('first_name' => 'Steve',
           'middle_initial' => 'S',
           'last_name' => 'Finkelstein',
           'room_number' => '301'
           'cpt_id' => '1');

$this->insert_patient($p);
...

function insert_patient($p) {
        log_message('debug', "testing for \$p: ".print_r($p, TRUE));
        $this->db->insert('ms_patients', $p);
    }
#3

[eluser]Pygon[/eluser]
the problem is that you have an array of arrays (multi-dimensional)
as you can see,

$p[0]['first_name'] = "Steve"
where
$p['first_name'] = "Steve"
is expected.

I would take a look at how you're creating the array.
#4

[eluser]gtech[/eluser]
lol, we both agree then Wink




Theme © iAndrew 2016 - Forum software by © MyBB