I make a PHP request to the database to find a record where the code of the city of departure and the code of the city of arrival are equal to those requested by the user:
$query = "SELECT * FROM special_offers WHERE to_iata = '{$to_iata}' AND from_iata = '{$from_iata}'"; $result = pg_query($query) or die('Query failed: ' . pg_last_error()); Now I have only one record of suitable data in the database, but I cannot figure out how to get it right.
I process the data, trying to collect the values of one particular key into an array:
$rows = pg_fetch_assoc($result); foreach($rows as $row) { array_push($hashes, $row['data_hash']); } But in fact, it turned out that one record is not provided in the form of a nested array with a zero index, but simply in the form of a single array in the format key => value . How can I properly request data from a database so that an array of records will come to me, and not one record by an array? I tried to use pg_fetch_assoc() instead of pg_fetch_assoc() , but this did not change anything, only additional keys were added.