【问题标题】:PHP - Send an array from the first page and get it on the second pagePHP - 从第一页发送一个数组并在第二页获取它
【发布时间】:2018-11-21 15:11:04
【问题描述】:

我正在尝试将包含其值的数组从第一页发送到第二页。在第二页上,我想要发生的是发送的数组值将被传输到一个新数组。 这是我目前的进度:

Report_Status.php 的片段代码(首页/来源,其中 具有值的数组已初始化)

$message = array(
            'title' => 'Report Approved!',
            'body' => 'Thank you for reporting! We already approved/verified your report as a legit fire incident. Wait for the firefighters to arrive.'
        );
        while ($User_Row = mysqli_fetch_array($Retrieve_User, MYSQLI_ASSOC)){
            $User_Token[] = $User_Row['User_Token'];
        }
       send_notification($User_Token, $message); //calling a function of the second page. 
//I will replace the it from calling a function to redirecting to a specific web link

第一页从数据库中检索特定数据(即用户的令牌)并将其存储到数组中 ($User_Token[])。初始化。

Push_User_Notification.php 的片段代码(第二页/目的地,将接收包含其值的数组。

//Here: there should be the code for catching/receving the array
$Retrieve_Target_Tokens_Query = "SELECT * FROM User WHERE User_Token = $tokens";
$Retrieve_Target_Tokens = mysqli_query($Connection, $Retrieve_Target_Tokens_Query);
$tokens = array();

if(!$Retrieve_Target_Tokens){
    echo "<script type = 'text/javascript'> alert('Server Error: Could retrieve tokens from database because of this error: ". mysqli_error($Connection)."') </script>";
}

if(mysqli_num_rows($Retrieve_Target_Tokens) > 0){
    while($Token = mysqli_fetch_array($Retrieve_Target_Tokens)){
        $tokens[] = $Token['User_Token'];
    }
}
$message = array("message" => "Your Report has been approved by an admin! Please wait for firefighter/s to arrive.");    
send_notification($tokens, $message);

function send_notification ($tokens, $message)
{
//Process of Firebase sending notification here (No problem on this function)
}

问题:

  1. 如何从一个页面发送数组并成功接收到另一个页面?

附:此代码仅向特定的 android 用户发送推送通知。

【问题讨论】:

    标签: php sql arrays webpage


    【解决方案1】:

    您可以使用 Session 变量链接:http://php.net/manual/en/reserved.variables.session.php

    如果您想通过 Javascript 调用来传递它,也可以使用 JSON 传递它。

    希望对你有帮助:)

    【讨论】:

      【解决方案2】:

      我会为此使用会话。

      这是一个与您需要的答案类似的问题:Pass array from one page to another

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多