Refresh of an <input> containing Database values

Asked

Viewed 37 times

1

Hello let’s start explaining what I need kkk

Basically it is a game where I attack, after attacking it inserts in DB the CD turns, and at each new attack reduces the time by 1, what I wanted to do was he take the value of the bank and if the value exists or is >0 it puts the Attack in Cooldown, until then works well with this code

<?php
    while($tecnica=mysql_fetch_assoc($tabela_tecnica_o)){   
    $tecnica_cd = $db->query("SELECT * FROM `batalha_npc_tecnicas` WHERE `jogador`='".$_SESSION['personagem']."' AND `tecnica_id`='".$tecnica['tecnica_id']."'");
    $tecnica_cd = $db->fetch($tecnica_cd);
    // Aqui ele busca a CD no Banco de Dados e Retorna
    ?>
   <script type="text/javascript">
    setInterval(function () {
        if('<?=$tecnica_cd['cd']?>'>0){
        $("#tec-<?=$tecnica['id']?>").css('opacity',0.5);
        }
    }, 1000);
        </script>

However I noticed that even he giving "refresh" in Attack to update the CD he does not update the value searched in DB, only when I give F5 on the page... could someone help me with this? Input in case of doubt

<input type="submit" style="font-size:20px;color:#fff;border:0px;background:url(images/tecnicas/<?=$tecnica['tecnica_id']?>.png);float:left;margin-right:7px;height:90px;cursor:pointer;width:110px;background-size:110px 90px;" id="tec-<?=$tecnica['id']?>" value="" class="teste4" title="<?=$texto?>" data="<?=$tecnica['id']?>">

1 answer

2


Good morning buddy

Your problem is that your parole to trigger the action you want, only happens when you update the page, it probably should happen because you don’t have a Rigger (trigger) that fires the event.

I’ll give you another example that’ll get you thinking. Let’s say we have a PHP code on the page, as you should know the PHP it is interpreted by the server, so most of its triggers will be related to server events. The JS it is "interpreted" by the browser, so events in the browser will trigger most of its events.

In short, your code is pretty bad to read. But I advise you to move all this logic to the JS part, you can supervise this attack button, and when it is triggered you make a request for some endpoint for your php server.

  • I’m working directly on . js to do this I imagine it’s like you said &#xA; if(datas.t_cd) $("#tec-"+datas.t_cd).attr('disabled', 'disabled').css('opacity',0.5).val(datas.t_turnos_cd);&#xA; &#xA; if(datas.t_desblock_o) $("#tec-"+datas.t_desblock_o).removeAttr('disabled').css('opacity',1).val(""); &#xA; &#xA;&#However it only does 1 at a time when the button is clicked and not both

Browser other questions tagged

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