消息:count():参数必须是在centos上实现Countable codeigniter的数组或对象 [英] Message: count(): Parameter must be an array or an object that implements Countable codeigniter on centos

查看:70
本文介绍了消息:count():参数必须是在centos上实现Countable codeigniter的数组或对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看我的查询

Select * from join_chat where
(user_1 = '24' and user_2 = '26') or
(user_1 = '26' and user_2 = '24')

请从我的api解决此错误的建议

please advice with a solution to this error from my api

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>


</div>{"responce":true,"data":"20"}

2020-05-09 23:16:43.302 28439-30249 / techline.carsapp W / System.err:org.json.JSONException:值选择类型java.lang.String不能被转换为JSONObject
2020-05-09 23:16:43.302 28439-30249 / techline.carsapp W / System.err:at org.json.JSON.typeMismatch(JSON.java:112)
2020-05-09 23:16:43.302 28439-30249 / techline.carsapp W / System.err:at org.json.JSONObject。((JSONObject.java:163)
2020-05-09 23:16: 43.302 28439-30249 / techline.carsapp W / System.err:位于org.json.JSONObject。(JSONObject.java:176)
2020-05-09 23:16:43.303 28439-30249 / techline.carsapp W /System.err:在util.CommonAsyTask.doInBackground(CommonAsyTask.java:104)
2020-05-09 23:16:43.303 28439-30249 / techline.carsapp W / System.err:在util.CommonAsyTask。 doInBackground(CommonAsyTask.java:23)
2020-05-09 23:16:43.303 28439-30249 / techline.carsapp W / System.err:at android.os.AsyncTask $ 2.call(A syncTask.java:333)
2020-05-09 23:16:43.303 28439-30249 / techline.carsapp W / System.err:at java.util.concurrent.FutureTask.run(FutureTask.java:266)
2020-05-09 23:16:43.303 28439-30249 / techline.carsapp W / System.err:at android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:245)
2020 -05-09 23:16:43.303 28439-30249 / techline.carsapp W / System.err:at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2020-05-09 23: 16:43.303 28439-30249 / techline.carsapp W / System.err:at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641)
2020-05-09 23:16:43.303 28439 -30249 / techline.carsapp W / System.err:at java.lang.Thread.run(Thread.java:764)

消息:count():参数必须是实现的数组或对象可数

2020-05-09 23:16:43.302 28439-30249/techline.carsapp W/System.err: org.json.JSONException: Value Select of type java.lang.String cannot be converted to JSONObject 2020-05-09 23:16:43.302 28439-30249/techline.carsapp W/System.err: at org.json.JSON.typeMismatch(JSON.java:112) 2020-05-09 23:16:43.302 28439-30249/techline.carsapp W/System.err: at org.json.JSONObject.(JSONObject.java:163) 2020-05-09 23:16:43.302 28439-30249/techline.carsapp W/System.err: at org.json.JSONObject.(JSONObject.java:176) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at util.CommonAsyTask.doInBackground(CommonAsyTask.java:104) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at util.CommonAsyTask.doInBackground(CommonAsyTask.java:23) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:333) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 2020-05-09 23:16:43.303 28439-30249/techline.carsapp W/System.err: at java.lang.Thread.run(Thread.java:764)

Message: count(): Parameter must be an array or an object that implements Countable

文件名:controllers / Api.php

Filename: controllers/Api.php

行号:801

    <p>Backtrace:</p>

下面控制器中的方法

public function send_chat_data()
{
    $this->load->library('form_validation');
    $this->form_validation->set_rules('join_id', 'join_id', 'trim|required');
    $this->form_validation->set_rules('sender_id', 'sender_id', 'trim|required');
    $this->form_validation->set_rules('message', 'message', 'trim|required');

    if ($this->form_validation->run() == false) {
        $data["responce"] = false;
        $data["error"] = 'join id is required';
    } else {
        $post_date=date("Y-m-d m:i:s");
        $send_chat = array(
                               "join_id"=>$this->input->post("join_id"),
                               "sender_id"=>$this->input->post("sender_id"),
                               "message"=>$this->input->post("message"),
                               "created_date"=>$post_date
                               );

        $this->db->insert("chat", $send_chat);
        $insertid = $this->db->insert_id();

        $q = $this->db->query("Select * from join_chat where join_id= '".$this->input->post("join_id")."' limit 1");
        $recever_id = 0;
        $row = $q->row();
        if ($row->user_1 == $this->input->post("sender_id")) {
            $recever_id = $row->user_2;
        } else {
            $recever_id = $row->user_1;
        }
        $q2 = $this->db->query("Select * from chat where chat_id= '".$insertid."' limit 1");


        $chat = $q2->row();
        $data["responce"] = true;
        $data["data"] = $chat;



        $q_fcm = $this->db->query("Select * from users where user_id= '".$recever_id."' limit 1");
        $row_fcm = $q_fcm->row();

        $registatoin_ids =$row_fcm->user_gcm_code;


        $message["title"] = $this->config->item('app_name');
        $message["message"] = $this->input->post("message");
        $message["image"] = "";
        $message["created_at"] = date("Y-m-d h:i:s");
        $message["obj"] = $chat;

        $this->load->helper('gcm_helper');
        $gcm = new GCM();
        //$result = $gcm->send_topics("/topics/rabbitapp",$message ,"ios");

        $result = $gcm->send_notification(array($registatoin_ids), $message, "android");
    }
    echo json_encode($data);
}

错误来自下面的行

$row = $q->row();


推荐答案

问题是我所看到的您正在尝试计算非数组或不可数对象。



思路

The problem in your question is as I see is that you're trying to count a non-array or non-countable object.

Thoughts


  1. 在您的整个代码中,您尚未编写 count(),这似乎是
    引起问题,为什么?

  2. 为什么限制$ b时为什么要计算 $ q-> row(); $ b结果等于1个您自己 //正如您所说的,这里的问题是$ row = $ q-> row();

  1. In your entire code you haven't written the count() which seems to be causing the problem, why?
  2. Why do you need to count $q->row(); when you're limiting the result to 1 yourself // as you said the problem is here $row = $q->row();

可能的解决方案



当您使用 row( ) $ q-> row(); 您会得到不可数对象

Possible Solution

When you use row() ie $q->row(); you get a non-countable object,

// row() dummy data
stdClass Object
(
    [id] => 15
    [event_id] => 3
    [event_image] => c1fa8a5d5505047251fd928aa312b16c.jpg
)

但是当您使用 result() $ q-> result(); ,它将导致对象数组或 result_array()的情况,即使您将它们限制为一个数组,也可以是一个数组。

but when you use result() ie $q->result();, it will result in an array of objects or in the case of result_array(), an array of arrays, even if you limit them to one.

// result() dummy data -- same as result_object()
(
    [0] => stdClass Object
        (
            [id] => 15
            [event_id] => 3
            [event_image] => c1fa8a5d5505047251fd928aa312b16c.jpg
        )

)

// result_array() dummy data
Array
(
    [0] => Array
        (
            [id] => 15
            [event_id] => 3
            [event_image] => c1fa8a5d5505047251fd928aa312b16c.jpg
        )

)

它们现在都是数组,因此是可数的。

Both of them are now an array and hence countable.


因此,如果必须计数,请使用 $ q-> result();
另外,如果要
计算结果的数量 $ q-> row(); 有,则可以使用

count((array)($ q-&row;()));
在这里将返回3。 {id},{event_id},{event_image} 。在这里

So, if you must count, use $q->result();
Also, if you want to count the number of "results" $q->row(); has, you can use
count((array) ($q->row()));
which will return 3 here. {id}, {event_id}, {event_image}. Read more about it here

希望它对您有帮助。

这篇关于消息:count():参数必须是在centos上实现Countable codeigniter的数组或对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆