Query results to array

I have this query : <?php
$conn = pg_pconnect(“host=localhost dbname=go user=go”);
if (!$conn) {
echo “An error occured.\n”;
exit;
}
$result = pg_query($conn, “SELECT phones.phone FROM phones”);
if (!$result) {
echo “An error occured.\n”;
exit;
}
while ($row = pg_fetch_row($result)) {
echo “$row[0],\n”;
}
?>
Im trying to send all the output from the query to this script for the numbers variable, each row must have a , at the end then a new line like my echo statement. Any help would be greatly appreciated. I tried a include statement but its not working.

$url = ‘https://www.callfire.com/cloud/1/sms/send’;
$params = array(
‘apikey’ => ‘xxxxx’,
‘message’ => ‘Tornado Warning for your Geo-Location’,
‘numbers’ => ‘include ‘q.php’;’
);
$http = curl_init($url);
curl_setopt($http, CURLOPT_POST, true);
$query = http_build_query($params);
curl_setopt($http, CURLOPT_POSTFIELDS, $query);
$header = array(‘Content-Type: application/x-www-form-urlencoded’);
curl_setopt($http, CURLOPT_HTTPHEADER, $header);
curl_setopt($http, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($http);
$error = curl_error($http);
if($error != null)
{
echo “Error: $error\n”;
throw new Exception($error);
}
echo “Alert Sent”;
?>

1st - Read the call fire API documentation so you can better understand the data structures : http://www.callfire.com/dev/index.php/SMS_API

2nd - IF YOU CAN add the API call to a function inside the application making the database call:

[php]
sendCallfireSMS($number){
$url = ‘https://www.callfire.com/cloud/1/sms/send’;
$params = array(
‘apikey’ => ‘xxxxx’,
‘message’ => ‘Tornado Warning for your Geo-Location’,
‘numbers’ => $number // call fire allows numerous numbers separated by commas so you could store multiple #'s in array and loop here
);
$http = curl_init($url);
curl_setopt($http, CURLOPT_POST, true);
$query = http_build_query($params);
curl_setopt($http, CURLOPT_POSTFIELDS, $query);
$header = array(‘Content-Type: application/x-www-form-urlencoded’);
curl_setopt($http, CURLOPT_HTTPHEADER, $header);
curl_setopt($http, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($http, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($http);
$error = curl_error($http);
if($error != null)
{
echo “Error: $error\n”;
throw new Exception($error);
}
echo “Alert Sent”;
}

[/php]

3rd - change your resource while loop to =

while ($row = pg_fetch_row($result)) {
$number = $row[o]
}

let me know if that helps

PHP Parse error: syntax error, unexpected ‘}’ in /var/www/html/newwarn.php on line 14
Not sure where the problem is I’m just starting out in programing.

<?php $conn = pg_pconnect("host=localhost dbname=su user=x"); if (!$conn) { echo "An error occured.\n"; exit; } $result = pg_query($conn, "SELECT phones.phone FROM phones"); if (!$result) { echo "An error occured.\n"; exit; } while ($row = pg_fetch_row($result)) { $number = $row } sendCallfireSMS($number){ $url = 'https://www.callfire.com/cloud/1/sms/send'; $params = array( 'apikey' => 'xxxxx', 'message' => 'Tornado Warning for your Geo-Location', 'numbers' => $number // call fire allows numerous numbers separated by commas so you could store multiple #'s in array and loop here ); $http = curl_init($url); curl_setopt($http, CURLOPT_POST, true); $query = http_build_query($params); curl_setopt($http, CURLOPT_POSTFIELDS, $query); $header = array('Content-Type: application/x-www-form-urlencoded'); curl_setopt($http, CURLOPT_HTTPHEADER, $header); curl_setopt($http, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($http, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($http, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($http); $error = curl_error($http); if($error != null) { echo "Error: $error\n"; throw new Exception($error); } echo "Alert Sent"; } ?>

[php]
while ($row = pg_fetch_row($result)) {
$number = $row;
}
[/php]

u forgot to end the statement with the semi colon

Now its PHP Parse error: syntax error, unexpected ‘{’ in /var/www/html/newwarn.php on line 16

That was just psuedo-code really to show you the right path :wink: but I unintentionally left out the function keyword so change sendCallfireSMS to function sendCallfireSMS($number)

Its still giving me errors.

not sure where line 16 is, but i see two possible things. 1, the comment in the params array probably needs to be on the outside of the ); so its not getting read into the array and 2, you have an extra } at the very end. i don’t see a matching {.

Sponsor our Newsletter | Privacy Policy | Terms of Service