Answer the question
In order to leave comments, you need to log in
How to customize output in array template?
The idea is this:
There is a page on it, a post request is made to search in ajax.php, which sends a request to an external API and receives an array
Ajax.php code:
$url = 'http://domen.ru/api/search.php';
$params = array(
'search' => $_POST['search'],
'key' => $secret_key,
);
$result = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)));
$result = json_decode($result, true);
if ($result) {
foreach ($result as $key => $value) {
$id = $value['id'];
$date = $value['date'];
$title = $value['title'];
$thumb = $value['thumb'];
include '../tpl/remotePostSearch.tpl';
}
}
Array
(
[0] => Array
(
[title] => Кофе
[date] => 30/04/2020
[id] => 5
[thumb] => /32894e4b.jpg
)
[1] => Array
(
[title] => Чай
[date] => 30/04/2020
[id] => 4
[thumb] => 1528900394_clash-of-clans.png
)
)
<h2><?=$title?></h2>
<div>
<img src="http://domen.ru/images/<?=$thumb?>">
<p><?=$id?> :: <?=$date?></p>
</div>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question