Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP putting an array within an array using variable
    primarykey
    data
    text
    <p>I'm just wondering, is this correct? I can't find any guide for doing it this way, but I don't know how many elements regIds will have, so it seems like it needs to be done like this. regIds is the array. </p> <pre><code>$fields = array( 'registration_ids' =&gt; $regIds, 'data' =&gt; array( "message" =&gt; $message ), ); </code></pre> <p>Edit: full script with sensitive values omitted:</p> <pre><code>&lt;?php $name = $_POST['name']; $message = $_POST['message']; $latitude = $_POST['latitude']; $longitude = $_POST['longitude']; $url = "dburl"; $username = "dbusername"; $password = "password"; $db = "database"; mysql_connect($url, $username, $password); mysql_select_db($db); $sql = mysql_query("select chatId from Players natural join Accounts where account_state = 'O' and ABS(playerLat - '$latitude') &lt; 0.1 and ABS(playerLong - '$longitude') &lt; 0.1"); while($row = mysql_fetch_assoc($sql)) { $regIds[] = $row; } mysql_close(); $apiKey = "key"; // Set POST variables $urls = 'https://android.googleapis.com/gcm/send'; $fields = array( 'registration_ids' =&gt; $regIds, 'data' =&gt; array( "message" =&gt; $message ), ); $headers = array( 'Authorization: key=' . $apiKey, 'Content-Type: application/json' ); //Open connection $ch = curl_init(); // Set the url, number of POST vars, POST data curl_setopt( $ch, CURLOPT_URL, $urls ); curl_setopt( $ch, CURLOPT_POST, true ); curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) ); //Execute post $result = curl_exec($ch); // Close connection curl_close($ch); echo $result; ?&gt; </code></pre> <p>It doesn't return anything</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload