I have a database with a column "regId" in a table users What I want to do is select all rows but only that column (SELECT regId FROM users)
However, in PHP, I want this as
Array("the first row ID", "the second row ID", and so on)
I am building an app using the Google Cloud Messaging and the registration IDs are needed in an array like "Array("something", "something else")
Here's my code
<?php
session_start();
require_once("global.php");
$qry = "SELECT `regId` FROM `users` WHERE regId IS NOT NULL"; //Here's where the IDs are
$fetchQry = mysqli_query($connection, $qry);
// Replace with the real server API key from Google APIs
$apiKey = "/////";
// Replace with the real client registration IDs
$registrationIDs = array("","","",""); //heres how they need the IDs
// Message to be sent
$message = "somethinnnnnn";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $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, $url);
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));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
// 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;
//print_r($result);
//var_dump($result);
?>
And I have checked similar questions and they all use a while loop such as
$rows = [];
while($row = mysqli_fetch_array($result))
{
$rows[] = $row;
}
However, if I set the $registrationIDs variable equal to $rows or array($rows), it does not work! (even echoing them doesn't show the data)