put image in a PHP array

Asked

Viewed 574 times

0

I have an event counter on my game site, where I wanted a git to appear before the event name.

I need a hand where I would follow that order.

Next:
gif image.
zombie:

inserir a descrição da imagem aqui


php layout.

<div class="Themebox Eventos-Box" style="background-image:url(<?PHP echo $layout_name; ?>/images/themeboxes/eventos.png);">
    <img style="position:relative;top: 30px;left: 5px;" width="170" src="<?php echo $layout_name; ?>/images/themeboxes/bg_events.png">
    <div class="eventos" align=" ">
        <div class="evento-font" align="center">Proximo:</div>
        <div id="cdEventos" style="margin-top: 40px; font-size: 14px;" align="center">Carregando...</div>
    </div>
</div>

Function you have in the layout.php

function getEventos() {
            $.ajax({
                type: "POST", url: "eventos.php", data: "action=do",
                complete: function(data){
                    var data = data.responseText;
                    $("#cdEventos").html(data);

                }
            })
        };

Eventos.php

<?php 
date_default_timezone_set('America/Sao_Paulo');

$horaAtual = new DateTime();

$horarios = array(
    '1' => array('nome' => 'Zombie', 'hora' => '10:00:00', 'img' => '/images/eventos/zombie.gif'),
    '2' => array('nome' => 'Zombie', 'hora' => '13:00:00', 'img' => '/images/eventos/zombie.gif'),
    '3' => array('nome' => 'Zombie', 'hora' => '18:00:00', 'img' => '/images/eventos/zombie.gif'),

    '4' => array('nome' => 'Rush War', 'hora' => '12:00:00'),
    '5' => array('nome' => 'Rush War', 'hora' => '15:00:00'),
    '6' => array('nome' => 'Rush War', 'hora' => '21:00:00'),

    '7' => array('nome' => 'Defend The Base', 'hora' => '09:00:00'),
    '8' => array('nome' => 'Defend The Base', 'hora' => '17:00:00'),
    '9' => array('nome' => 'Defend The Base', 'hora' => '23:00:00'),

    '10' => array('nome' => 'Castle War', 'hora' => '20:00:00'),

    '11' => array('nome' => 'Capture The Flag', 'hora' => '11:00:00'),
    '12' => array('nome' => 'Capture The Flag', 'hora' => '14:00:00'),
    '13' => array('nome' => 'Capture The Flag', 'hora' => '19:00:00'),

    '14' => array('nome' => 'Good Time', 'hora' => '08:00:00', 'img' => '/images/eventos/good.png'),
    '15' => array('nome' => 'Good Time', 'hora' => '15:00:00', 'img' => '/images/eventos/good.png'),
    '16' => array('nome' => 'Good Time', 'hora' => '21:00:00', 'img' => '/images/eventos/good.png')


    );

foreach ($horarios as  $value) {
    $horaEventos = new DateTime($value['hora']);

    if ($horaAtual<$horaEventos) {
        $diff = $horaAtual->diff($horaEventos);

        echo $value['nome']. ": " ['img']. "<center/>". $diff->format('%H:%I:%S');
        break;
    }   
}

?>
  • 1

    It was not clear what to do and what your need.

  • This image I put on the theme is a counter, I wanted to appear a gif chosen by me as example https://i.imgur.com/Djvh9u9.gif before the name Zombie: Would image <br/> Zombie: 01:01:59

1 answer

1


I’ve already solved!.

inserir a descrição da imagem aqui


foreach ($horarios as  $value) {
    $horaEventos = new DateTime($value['hora']);

    if ($horaAtual<$horaEventos) {
        $diff = $horaAtual->diff($horaEventos);

        echo $value['img']. "<center/><br/>";
        echo $value['nome']. ": <center/>". $diff->format('%H:%I:%S');
        break;
    }   
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.