Viewed   76 times

Ok, so I have a form that is sending me arrays in the POST array. I am trying to read it like so:

$day = $this->input->post("days")[0];

This does not work. PHP says "unexpected '['". Why does this not work?

I fixed it by doing it this way:

$days = $this->input->post("days");
$day = $days[0];

I fixed my problem, I'm just curious as to why the 1st way didn't work.

 Answers

3

Array derefencing from function calls isn't supported by PHP. It's implemented in the SVN trunk version of PHP, so it will likely make it into future versions of PHP. For now you'll have to resort to what you're doing now. For enumerated arrays you can also use list:

list($day) = $this->input->post("days");

See: http://php.net/list

Wednesday, December 14, 2022
 
2

Okay, I think what you need to do is set an alias for the id field in the comments table:

function com_control() {
    $this->db->select('entry_id, comments.id AS comment_id, comment, title');
    $this->db->from('comments');
    $this->db->join('posts', 'comments.entry_id = posts.id');
    $query = $this->db->get();

    return $query->result;
}

Then you can reference the comments.id field as simply $row->comment_id:

$this->table->set_heading('Entry ID', 'Comment ID', 'Comment', 'Title');

foreach ($comm_control as $row ) {
    $this->table->add_row(
        $row->entry_id,
        $row->comment_id,
        $row->comment,
        $row->title             
    );      
}

echo $this->table->generate();

Actually if the column 'id' is unique to the comments table, then you could just use $row->id; the problem arises when you are joining tables that both have a column named the same; it becomes ambiguous and the computer won't know what you're referencing.

Saturday, August 20, 2022
 
raz
 
raz
4

Hm, understand. As I see the subquery's source code in line 27, it wants to call _compile_select or get_compiled_select. If you can check in CI's DB_active_rec.php the _compile_select is protected so you can't access from Subquery (it isn't subclass of db).

Possible solution: _compile_select() should public or class Subquery should be extend of CI's db class. I think you should report this to author of Subquery.

Or you can extend the CI's db class :)

Sorry - I want to write it as a comment.

Sunday, December 18, 2022
 
ghazi
 
3

Try this code it might help you :

Here dashboard is the name of controller

//this will route as localhost/appFolder/admin/index
  $route['admin'] = 'dashboard'; // for your index page

//this will route as localhost/appFolder/admin/method_name
 $route['admin/(:any)'] = 'dashboard/$1';

//this will route as localhost/appFolder/admin/method_name/param1
$route['admin/(:any)/(:any)'] = 'dashboard/$1/$2';

Link the route Like

// for your index page
<a href="<?php echo base_url('admin/index'); ?>"></a>

// for your other pages
<a href="<?php echo base_url('admin/method_name'); ?>"></a>

To link the other controller defined just like

 <a href="<?php echo base_url('otherControllerName/method_name'); ?>"></a>
Sunday, September 4, 2022
 
2

I think you need to modify the output of the model. In the controller try this(just modify the columns):

$rec = $this->category_model->getCategoryMembers();
$new_rec = array();
foreach ($rec as $k => $v) {
    $new_rec[$v->category][] = $v->member;
}
$data['members'] = $new_rec;

And for the view :

<?foreach ($members as $k => $v):?>
  <h3><?php echo $k ?></h3>
    <?if($v):?>
        <?foreach ($v as $m):?>
            <p><?=$m?></p>
        <?endforeach;?>
    <?endif;?>
<?endforeach;?>
Thursday, August 11, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :