Include variable in json result [closed]

0
if($_GET['operacao'] == 'banners'){
    header('Content-Type: application/json; charset=utf-8'); 
    $rs = $mysqli->query("SELECT foto AS image FROM banners");
    $registros = mysqli_num_rows($rs);

    $arr = array();
    $url = "http://www.site.com.br/";
    while($row = $rs->fetch_assoc()) { 
        $arr[] = $row;
    } 

    $json_encode = json_encode($arr); 
    echo $json_encode; 
}

This code above generates a json like this:

[
  {"image": "freightliner.jpg"},
  {"image": "sailing-ships.jpg"},
  {"image": "taxi-cab.jpg"
  }
]

How to make the URL appear and look like this:

[
  {"image": "http://www.site.com.br/freightliner.jpg"},
  {"image": "http://www.site.com.br/sailing-ships.jpg"},
  {"image": "http://www.site.com.br/taxi-cab.jpg"
  }
]
    
asked by anonymous 11.12.2015 / 18:20

1 answer

1

Just do the concatenation of the variables.

$url = "http://www.site.com.br/";
while($row = $rs->fetch_assoc()) { 
    $arr[] = $url.'/'.$row['image'];
} 

In the variable $row , between colchetes you need the name of the foto column.

    
11.12.2015 / 18:23