dongzhabo2796 2015-11-02 06:22
浏览 39

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

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.

  • 写回答

1条回答 默认 最新

  • dtl4521 2015-11-02 13:14
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算