0

My controller function:

public function c_content()
{
    $data['story_id']=$this->input->post('story_id');
    $data['template_id']=$this->input->post('template_id');
    $data['content']=$this->input->post('content');
    $ary_len=count($data); // give me output 1 where as i send 3 value 
    echo $ary_len;
}

From here I send value story id, template id and content, where as the content have a multiple input values.

My view:

<form action="<?=base_url('c_signup/c_content')?>" method="post" >
    <input type="text" name='template_id' value=<?php echo  $template_id ?> >
    <input type="text" id="story_id" name='story_id' value=<?php echo $story_id ?> >

    <div class="abc">

    <?php
        $story_content1=$txt;

        // here some code is exected and give me result 3
        $result = count($out); // output 3

        for ($x = 0; $x < $result; $x++) {
            echo("
                  <input type='text' value='". $out[$x] ."' name='content'>// here i set name of txt field as content
            ");
    ?>
    <?php
        }
    ?>

    </div>
    <button value="submit">save</button>
</form>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
misbah
  • 183
  • 1
  • 2
  • 8

2 Answers2

0

Try this

<input type='text' value='". $out[$x] ."' name='content[]'>
0

You are counting the entire $data array, not $data['content'].

I believe you want $ary_len = count($data['content']); in your PHP.

You'll need to also change name="content" to name="content[]" in your HTML.

Look at this answer for an explanation on what happens when you count an associative array.

Community
  • 1
  • 1
Mikey
  • 6,728
  • 4
  • 22
  • 45