【发布时间】:2015-12-30 23:15:09
【问题描述】:
我从 mysql 获取数据作为 json 编码。一切正常,除了图像路径,它不是数据库中的绝对路径——它只是一个相对路径,例如images/starwars.jpg。我正在开发一个移动应用程序,并希望获得显示图像的绝对路径。
它应该显示为http://sample.com/images/starwars.jpg。
可以通过更改数据库中的名称路径来完成,但我正在寻找替代解决方案。
我使用的获取图片路径的字段是:$row['path']=$row['path'];
编码json对象的php代码是:
<?php
$sql = "SELECT DATE_FORMAT(movie.filmReleaseDate,'%d %b %Y')filmReleaseDate, movie.filmName, movie.filmDirector, movie.url, images.path FROM movie INNER JOIN images ON movie.filmId = images.filmId WHERE movie.filmReleaseDate >= NOW() GROUP by images.filmId ORDER BY DATE(films.filmReleaseDate) LIMIT 0 , 12";
$result = mysqli_query($conn,$sql);
$json = array();
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))//loop through the retrieved values
{
$row['filmName']=htmlentities(stripslashes($row['filmName']));
$row['filmDirector']=htmlentities(stripslashes($row['filmDirector']));
$row['filmReleaseDate']=$row['filmReleaseDate'];
$row['url']=$row['url'];
$row['path']=$row['path'];
$json[] = $row;//build an array
}
echo json_encode(array('upcomingFilms' => $json));
?>
【问题讨论】: