xjermx Posted June 18, 2010 Share Posted June 18, 2010 Hi, total newbie here. Working on teaching myself PHP and codeigniter, largely through a cargo cult style of learning. I've spent a few days banging head against the wall trying to do something that I think is relatively simple. I have an array which I'll pulled via a function in my model from a mysql database. $data = $this->smoke_model1->list_users(); print_r($data); gives me: Array ( [multi] => Array ( [0] => stdClass Object ( [id] => 1 [name] => jerm1 [ip] => ) [1] => stdClass Object ( [id] => 2 [name] => name [ip] => ) [2] => stdClass Object ( [id] => 3 [name] => 0 [ip] => ) [3] => stdClass Object ( [id] => 4 [name] => 0 [ip] => ) [4] => stdClass Object ( [id] => 5 [name] => asdf56 [ip] => ) [5] => stdClass Object ( [id] => 6 [name] => asdf57 [ip] => ) [6] => stdClass Object ( [id] => 7 [name] => asdf58 [ip] => ) [7] => stdClass Object ( [id] => 8 [name] => asdf59 [ip] => ) [8] => stdClass Object ( [id] => 9 [name] => 0 [ip] => ) [9] => stdClass Object ( [id] => 10 [name] => bsdf2 [ip] => ) [10] => stdClass Object ( [id] => 11 [name] => laksdjie11 [ip] => ) [11] => stdClass Object ( [id] => 12 [name] => bargle2 [ip] => 75.66.223.193 ) [12] => stdClass Object ( [id] => 13 [name] => Booblesnort [ip] => 75.66.223.193 ) ) ) I am trying to fiddle with how that array is setup. Ultimately I'm trying to pass the data to a view, display the data with checkboxes and a submit button, and then based on which are checked, pass them back to the model to be deleted from the mysql table. I've successfully passed the data to the view, and gotten it to display, but I think that I need to tweak the array - the lack of key names is throwing me off. I've managed to make the following code work for testing: $data['multi'] = array( array('name'=> 'xid[]','id'=>'78','name2'=>'Bob Barker','ip'=>'5465465465','value'=>'hi my name is Bob'), array('name'=> 'xid[]','id' => '17','name2'=>'Joe Smith','ip'=>'255.255.255.0','value' => 'Hi my name is Joe'), array('name'=> 'xid[]','id' => '14', 'name2' => 'Sam Turner','ip' =>'127.0.0.1','value'=> "Hi my name is Sam"), ); because I can use foreach ($multi as $var) and make calls to $var and $var['name'] etc. Hence, my assumption is that if I can plug the values from my sql table into an array that has proper key names, then I can use them in the view. Is there a simpler way to do this? Quote Link to comment Share on other sites More sharing options...
cags Posted June 19, 2010 Share Posted June 19, 2010 Your array appears to actually be an array of objects, which are stored in your main array under the key 'multi'. To iterate through them you would want something along the lines of... foreach( $data['multi'] as $v ) { echo $v->id; echo $v->name; echo $v->ip; // etc } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.