简体   繁体   English

MySQLi Multi_Query帖子

[英]MySQLi Multi_Query Post

I am sending data to my PHP API using JSON. 我正在使用JSON将数据发送到我的PHP API。 I want to send a push notification to my Android user with this API. 我想使用此API向我的Android用户发送推送通知。 I am facing one strange issue in it. 我面临一个奇怪的问题。 From JSON, I am sending Mobile Number , Mobile Number Status and User Id . 从JSON,我正在发送Mobile NumberMobile Number StatusUser Id

I have two table in my database: 我的数据库中有两个表:

  1. user which has fields called id , fcm and fcm_enabled 具有名为idfcmfcm_enabled字段的user
  2. number_list which has fields called number , name and user_id number_list具有名为numbernameuser_id字段

Now I want to send a push notification to whichever number status we get from the JSON in 1 . 现在,我想向1从JSON获得的任何数字状态发送推送通知。 To send the notification it needs to check if fcm_enabled=1 , then it needs to get the fcm key from the fcm field from table 1 's user, and name from table 2 's name. 要发送它需要检查的通知fcm_enabled=1 ,那么它需要获得fcm从关键fcm字段从table 1的用户,并且nametable 2的名字。

It's working fine under normal conditions, but if two users have the same mobile number, then I am getting two notifications on one device, and one notification on the other. 在正常情况下,它可以正常工作,但是如果两个用户的手机号码相同,那么我在一台设备上会收到两个通知,而另一台设备上会收到一个通知。

I think there's something wrong in my query. 我认为查询中有问题。 Let me know if someone can help me solve my issue. 让我知道是否有人可以帮助我解决我的问题。 I have been trying from the last two days but, have had no success. 最近两天我一直在尝试,但是没有成功。

$number = $_GET["number"];
$status = $_GET["status"];
$userIds = $_GET["userId"];
$sql = "";
for($i = 0; $i < count($number); $i++) {
    if($status[$i] == 1) {
        $sqlSelect = "SELECT t2.name, t1.fcm, t1.fcm_enabled FROM user AS t1 INNER JOIN number_list AS t2 ON t1.id = t2.user_id WHERE t2.number = '$number[$i]'";
        $resultSelect = $conn->query($sqlSelect);
        if($resultSelect) {
            while($row = $resultSelect->fetch_row()) {
                if($row[2] == 1) {
                    sendFCM(array("title" => $row[0] . " is Online", "body" => ""), array("message" => ""), $row[1]);
                }
            }
        }
    }
}

Thanks. 谢谢。

If there is same number is for two users, may be it fetches duplicates records of users. 如果两个用户的号码相同,则可能是获取用户的重复记录。 "Group By" the number for fetching can help you. “分组依据”提取号码可以为您提供帮助。

Updated the query with following: 使用以下命令更新了查询:

$sqlSelect = "SELECT t2.name, t1.fcm, t1.fcm_enabled FROM user AS t1 INNER JOIN number_list AS t2 ON t1.id = t2.user_id WHERE t2.number = '$number[$i]'  GROUP BY t1.id";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM