如何在从我的数据库获取的每一行中添加实时计时计时器

时间:2017-02-04 01:04:26

标签: javascript php mysql ajax codeigniter

我需要显示将订单加载到我的监控页面的小时,分​​钟和秒,我从mysql db获取并使用foreach循环。我仍然是javascript的新手,我在计数计时器上遇到问题,这是从我的第一行结果执行相同的时间。

Here is my sample image

这是我的Ajax代码:

function mutation(arr) {
  var one=arr[0].toLowerCase();
  var two=arr[1].toLowerCase();

  var oneArr=one.split("");
  var twoArr=two.split("");
  
  console.log("Do all of '" + one + "' characters occur in '" + two + "'?");

  for(var i=0;i<oneArr.length;i++){
    console.log("Looking for " + oneArr[i]);

    // If any characters in two didn't occur in one, it fails
    var twoIndex = twoArr.indexOf(oneArr[i]);
    if(twoIndex === -1) {
      console.log("Can't find " + oneArr[i]);
      return false;
    } else {
      console.log("Found at index " + twoIndex + " in '" + two + "'");
    }
  }
  return true;
}

console.log(mutation(["hey", "hello"]));

console.log(mutation(["qrstu", "zyxwvutsrqponmlkjihgfedcba"]));

这是我的控制器

    /* AJAX request to checker */
    function check(){
        $.ajax({
            type: 'POST',
            url: 'http://localhost/kds1/monitor/checker',
            dataType: 'json',
            data: {
                counter:$('#dispatch-list').data('counter')
            }
        }).done(function( response ) {
            /* update counter */
            $('#dispatch-list').data('counter',response.current);
            /* check if with response we got a new update */
            if(response.update==true){
                if(response.patch==false){
                    $('#title-un').text('New Order Added');
                    $('#para-un').text('There are new addition to the order, kindly check the food preparation or miscellaneous tab. thanks!');
                    $('#update-notification').fadeIn(1500);
                    $('#update-notification').delay(3000).fadeOut(1500);
                    $('#order-list').html(response.orders);
                    $('#misc-list').html(response.misc);
                    $('#dispatch-list').html(response.dispatch);
                    $('#reject-list').html(response.reject);
                } else {
                    $('#order-list').html(response.orders);
                    $('#misc-list').html(response.misc);
                    $('#dispatch-list').html(response.dispatch);
                    $('#reject-list').html(response.reject);
                }
                //$('#counter-list').html(response.counters);
            }
        });
    }
    //Every 5 sec check if there is new update
    setInterval(check,5000);
    //end of checker

这是我的模型,这里是我显示计时计时器的所有按钮

public function checker()
{
    //set initial value of update to false
    $data['update'] = false;

    //get current counter
    $cc = $this->order_model->check_changes();
    foreach($cc as $row){
        $data['current'] = $row->counter;
    }

    if(isset($_POST) && !empty($_POST['counter']) && $_POST['counter']!=$data['current']){
        $data['orders']   = $this->order_model->get_order_buttons(1);
        $data['misc']     = $this->order_model->get_order_buttons(2);
        $data['dispatch'] = $this->order_model->get_order_buttons(3);
        $data['reject']   = $this->order_model->get_order_buttons(4);
        $data['update'] = true;
        $data['patch'] = true;
    }

    echo json_encode($data);
}

我有这个工作样本,我从这里得到但我不知道我应该把它放在哪里,如果我在我的foreach循环中包含跨度,它只是得到第一行。

public function get_order_buttons($id)
{
    $this->mysql->select('id, trans_no, room_no, date, HOUR(time_in) as hour, MINUTE(time_in) as minute, time_in, SUM(qty) as qty1, GROUP_CONCAT(description) as description, post, code, status, type');
    $this->mysql->from('orders');
       $date = date('Y-m-d');
       $dateMin = date('Y-m-d',(strtotime ( '-1 day' , strtotime ( $date) ) ));
       $where = "((`date` = '".$dateMin."' AND `time_in` >= '22:00:00') OR (`date` = '".$date."' AND `time_in` >= '00:00:00'))";
    $this->mysql->where($where);
    if($id == 1){
        //orders
        $this->mysql->where('status', 0);
        $this->mysql->where('type', 1);
    } elseif($id == 2){
        //misc
        $this->mysql->where('status', 0);
        $this->mysql->where('type', 0);
    } elseif($id == 3){
        //dispatch
        $this->mysql->where('status', 1);
    } elseif($id == 4){
        //rejected items
        $this->mysql->where('status', 3);
    }
    $this->mysql->group_by('trans_no');
    $this->mysql->order_by('date, hour, minute', 'ASC');

    $query = $this->mysql->get();
    $results = $query->result();

        $clr = '';
        $result = '';
        foreach($results as $row){
            if($row->status == 0 && $row->type == 1){
                $btn = 'onclick="show_order('.$row->trans_no.')"';
                $clr = 'btn-success';
            }elseif($row->status == 0 && $row->type == 0){
                $btn = 'onclick="show_misc('.$row->trans_no.')"';
                $clr = 'btn-success';
            }elseif($row->status == 1){
                $btn = 'onclick="show_dispatch('.$row->trans_no.')"';
            }elseif($row->status == 3){
                $btn = 'onclick="show_reject('.$row->trans_no.')"';
                $clr = 'bg-navy';
            }
            $result .= '<a '.$btn.' class="btn '.$clr.' btn-success btn-social" style="margin-top:5px;margin-bottom:5px;margin-right:10px;">
                        <i class="fa">'.$row->room_no.'</i> 00:00:00 
                    </a>';
        }
    return $result;
}

its already working here, but i really need a javascript the will make it real-time counting-upward

0 个答案:

没有答案