我想在点击客户名称表单下拉列表时显示数据,它只显示该客户的消息和输入日期

My code works properly, it is display all messages and entry dates. I want to display message and entry date when I select customer name from drop down list.

Here is my controller CustomerlifecycleController

    public function actionCustomerlifecycleanalytic() {                           
     $customername = Customer::model()->findall("store_id='" . Yii::app()->session['store_id'] . "'");
     $customerlifecycle = CustomerLifecycle::model()->findAll();
     $this->renderPartial('customerlifecycleanalytic', array( 'customername' => $customername, 'customerlifecycle' => $customerlifecycle), false, true);
}

Here is my view file customerlifecycleanalytic.php Dropdown list Customer name fetch from customer model and there is column name id for customer

   <select class="form-control selectpicker customerfilter">
        <option value=''>Select Customer</option>

        <?php
        if (isset($customername)) {
            foreach ($customername as $customernames) {

                echo '<option value="' . $customernames['id'] . '" >' . $customernames['firstname'].'&nbsp'. $customernames['lastname']. '</option>';
            }
        }
        ?>
    </select>

Message and entry date fetch from Customerlifecycle model there is column name is customer_id

    $msg = '<li {classstr}>
                    <div class="tl-circ">
                    </div>
                    <div class="timeline-panel">

                        <div class="tl-body">
                            <p>
                               {msg} on {date}</p>

                        </div>
                    </div>
                </li>';

    $cnt = 0;
    $htmlstring = '';
    foreach ($customerlifecycle as $key => $row) {
        $htmlstring .= $msg;
        $classString ='';
        if ($cnt % 2 == 0) {
            $classString = " class='timeline-inverted' ";
        }
        $htmlstring = str_replace("{classstr}", "$classString", $htmlstring);
        $htmlstring = str_replace("{msg}", "$row->message", $htmlstring);
        $htmlstring = str_replace("{date}", "$row->entrydate", $htmlstring);
        $cnt++;
    }


   echo $htmlstring;
    ?>

My code is already running completely but I want when I select customer name form drop down list at that time it will display only that customer's message and entry date.

To display selected customer's message and entry date, you can call javascript function on onChange event of dropdownlist as follows:

<script type="text/javascript" language="Javascript">
        function submitForm() {
                document.getElementById("form-id").submit();
        }
</script>
<select class="form-control selectpicker customerfilter" name="Customer[id]" onChange="js: return submitForm();">

Using this javascript function, submit the form and make changes in your controller as follows:

public function actionCustomerlifecycleanalytic() {                           
     $customername = Customer::model()->findall("store_id='" . Yii::app()->session['store_id'] . "'");
         $strCondition = "";
         if(isset($_POST['Customer'])) {
                if (!empty($_POST['Customer']['id'])) {
                        $strCondition .= "store_id = '" . Yii::app()->session['store_id'] . "' AND customer_id = '" . $_POST['Customer']['id'] . "'";
                }
        }
        $customerlifecycle = CustomerLifecycle::model()->findAll($strCondition);
        $this->renderPartial('customerlifecycleanalytic', array( 'customername' => $customername, 'customerlifecycle' => $customerlifecycle), false, true);
}

Hope this helps!