【发布时间】:2014-05-31 16:31:36
【问题描述】:
我正在使用 PHP 来获取一个 JSON 数组以供 Android 应用程序检索。
其中一个字段名为strImagen,此字段存储文件名。
我需要将 URL 路径添加到文件名,作为要进行 JSON 编码的行的一部分。
例子:
如果
$row['strImagen'] = '123456789.png'
应该是
htttp://myserverURL/images/123456789.png
这是我创建 JSON 数组的代码的 PHP 部分:
// query the application data
$sql = "SELECT * FROM tbempresas";
$result = mysqli_query($con, $sql);
// an array to save the application data
$rows = array();
// iterate to query result and add every rows into array
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$rows[] = $row;
}
// close the database connection
mysqli_close($con);
// echo the application data in json format
echo json_encode($rows);
我需要你的帮助...谢谢
【问题讨论】:
-
那么你有没有尝试过这样做?毕竟你只是在谈论基本的字符串连接。
-
@MikeBrant,谢谢,但我认为这比基本的字符串连接更复杂,至少对我来说是 PHP 级别,我相信你是专家,但我不是。无论如何谢谢你。
-
@msvasco 并不比基本的字符串连接复杂。请参阅下面 AbraCadaver 的答案。