I have some PHP that retrieves data from a database table and populates an array depending on a query.
I want to merge two fields together, they are 'organisation' and 'full address' and store this in one item under 'ADDRESS'. How can I add both rows together?
I have tried 'ADDRESS' => $row['organisation'] + $row['full_address'], but I don't think I am looking along the correct lines.
<?php
if (isset($_GET['query'])) {
// Connect to our database
$conn = pg_connect("host=myhost port=myport dbname=mydb user=myuser password=mypass");
// Retrieve the query
$query = $_GET['query'];
// Search the database for all similar items
$sql = pg_query($conn, "SELECT * FROM addresses.llpg_basic WHERE (lpi_logical_status_desc = 'Approved / Preferred LPI' OR lpi_logical_status_desc = 'Provisional LPI') AND full_address ILIKE '%{$query}%'");
$array = array();
while ($row = pg_fetch_array($sql)) {
$address = array(
'ADDRESS' => $row['full_address'],
'POSTCODE' => $row['postcode'],
'UPRN' => $row['uprn'],
'USRN' => $row['usrn'],
'X' => $row['xref'],
'Y' => $row['yref']
);
array_push($array, $address);
}
sort($array);
$jsonstring = json_encode($array);
// Return the json array
echo $jsonstring;
}
?>
'ADDRESS' => $row['organisation'] .$row['full_address'],'ADDRESS' => $row['organisation'] + $row['full_address']you mean to try use'ADDRESS' => $row['organisation'] . ' ' . $row['full_address']. the.is the concatenate operator.