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 stay 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"
}
]
Focus on the client side, with javascript, instead of doing issno by the server with php. To avoid unnecessary data traffic and process.
– Daniel Omine
@Danielomine How do you do it?
– Tiago
post the javascript code that reads the json result, if you have.
– Daniel Omine
I’m doing like this:
<div class="galleria image-gallery-size widget uib_w_8 d-margins" data-uib="media/image_gallery" data-ver="0" data-sm-trigger="true" images-json="http://www.site.com.br//testeConexaoMobileJson.php?operacao=banners">
– Tiago
not that.. post the script that makes the ajax request. There must be some code there with something like this:
$.ajax({ .....
and thissuccess: function(response){
.. This thing usually goes between javascript tags. It’s a bit like this:<script type="text/javascript">
. Get it? Edita puts the question. Do not put here in the comment.– Daniel Omine
I don’t use it because the file
testeConexaoMobileJson.php
generates json on the screen as in the format demonstrated in the topic.– Tiago
?? How do you order the testConexaoMobileJson.php file? After all, something has to order and read the result of this script.
– Daniel Omine
Thus
<div class="galleria image-gallery-size widget uib_w_8 d-margins" data-uib="media/image_gallery" data-ver="0" data-sm-trigger="true" images-json="http://www.site.com.br//testeConexaoMobileJson.php?operacao=banners">
Straight up.– Tiago
vc has already posted this... Just understand that this is not enough. There must be some jquery plugin, javascript script that reads this url and makes the request.. That’s what you don’t understand. Post javascript code.
– Daniel Omine
Buddy, if I should actually post it, but there isn’t. Let’s let this concatenate part, you can help me with the
$url
turn up?– Tiago
I am not your "friend". Without your cooperation there is no help. You don’t seem to understand that you need to requisition and read the result of json. This I have commented more above, but I do not understand why you insist on not paying attention..
– Daniel Omine
@Danielomine, I’m sorry for the expression, and I’m sorry I can’t be of your assistance, but I really appreciate it. All the best for you, but if you want to help me only with including the URL, it will be of great help.
– Tiago
@Danielomine please help me with the
while
, include the variable url.– Tiago