Show record without page refresh

Good afternoon, I swear I've researched everything that is place, but I only see teaching how to create chat :'(

I am developing a project (Corporate TV style) for the company I work for, and the project was serving very well until the headquarters liked this project asked to implement in all other units (including the headquarters) and asked for some " too " things and it is in these "too" things that came to me this problem of updating automatically.

1. I'm not a professional, I only know the basics and I turn around with what I know;
2. as I learned everything on the internet the project may not be in the standard or current form;
3. I learned everything on the internet ;

The project works like this:

  1. RH inserts the information.
  2. is displayed in the index (according to the unit). Example: localhost / sicc / general / RJ / bangu (project / controller / function/parameter)
  3. inside the view (which I called a slide) shows all the images for that unit, all for the region (the function) the images and all the images it serves for all regions and units

I researched about several tools that apparently solves my problem, but as I said at the beginning "I only see teaching how to create chat", so I came to the SOpt to see if I can get some light or path to the resolution of my problem.

Project:

Controller:

public function rj($unidade = null)
{               
    if (!isset($unidade)) {
        redirect('aplicacao');
    } else {
        if (($unidade === "Caxias") || ($unidade === "caxias")) {
            $unidade = "Caxias";
            $this->load->view('layouts/inicio_slide');
            $this->load->model('slide_model', 'slide');
            $dados['todasR'] = $this->slide->todas_unidade($unidade);
            $dados['fotos'] = $this->slide->todas_fotos_publicas($unidade);
            $this->load->view('slide', $dados);
            $this->load->view('layouts/fim_slide');
        } elseif (($unidade === "Bangu") || ($unidade === "bangu")) {
            $unidade = "Bangu";
            $this->load->view('layouts/inicio_slide');
            $this->load->model('slide_model', 'slide');
            $dados['todasR'] = $this->slide->todas_unidade($unidade);
            $dados['fotos'] = $this->slide->todas_fotos_publicas($unidade);
            $this->load->view('slide', $dados);
            $this->load->view('layouts/fim_slide');
        } elseif (($unidade === "grio") || ($unidade === "GRIO")) {
            $unidade = "Grande Rio";
            $this->load->view('layouts/inicio_slide');
            $this->load->model('slide_model', 'slide');
            $dados['todasR'] = $this->slide->todas_unidade($unidade);
            $dados['fotos'] = $this->slide->todas_fotos_publicas($unidade);
            $this->load->view('slide', $dados);
            $this->load->view('layouts/fim_slide');
        } else {
            redirect('aplicacao');
        }
    }       
}

View:

<?php if((count($fotos) === 0) && (count($todasR) === 0)): ?>
    <div id="slides">
        <div class="slides-container foto-slide">
            <img src="<?php echo base_url('assets/images/wallpaper.jpg') ?>" class="foto-slide" >
        </div>
    </div>
<?php else: ?>
    <div id="slides">
        <div class="slides-container foto-slide">
            <?php foreach($fotos as $foto): ?>
                <img src="<?php echo base_url('assets/fotos/'.$foto['foto']) ?>" class="foto-slide" >
            <?php endforeach; ?>
            <?php if(isset($todasR)): ?>
                <?php foreach($todasR as $todaR): ?>
                    <img src="<?php echo base_url('assets/fotos/'.$todaR['foto']) ?>" class="foto-slide" >
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

Model:

public function busca_regional($id_regional)
    {
        $resultado = $this->db->select('*')
        ->where('id_regional', $id_regional)
        ->get('regionais');
        return $resultado->result();            
    }  
    public function busca_unidade($unidadeL)
    {
        $resultado = $this->db->select('*')
        ->where('unidade', $unidadeL)
        ->get('unidades');
        return $resultado->result();

    }
    public function busca_unidade_todas($id_regional)
    {
        $resultado = $this->db->select('*')
        ->where('id_regional', $id_regional)
        ->where('unidade', 'Todas')
        ->get('unidades');
        return $resultado->result();

    }
    public function todas_unidade($unidadeL)
    {
        $unidade = $this->busca_unidade($unidadeL);
        foreach ($unidade as $uni) {
            $id_regional_local = $uni->id_regional;
        }            
        $regional = $this->busca_regional($id_regional_local);
        foreach ($regional as $reg) {
            $id_regional = $reg->id_regional;
        }
        $toda = $this->busca_unidade_todas($id_regional);
        foreach ($toda as $tod) {
            $id_unidade = $tod->id_unidade;
        }

        $resultado = $this->db->select('*')
        ->from('fotos')
        ->where('id_regional', $id_regional)
        ->where('id_unidade', $id_unidade)
        ->where('publica', true)
        ->get();

        return $resultado->result_array();

    }
    public function todas_fotos_publicas($unidadeL)
    {
        $unidade = $this->busca_unidade($unidadeL);
        foreach ($unidade as $uni) {
            $id_unidade = $uni->id_unidade;
        }

        $resultado = $this->db->select('*')
        ->from('fotos')
        ->where('publica', true)
        ->where('id_unidade', $id_unidade)
        ->get();
        return $resultado->result_array();
    }

I'm sorry, if you happen to get confused.

Author: Edu Mendonça, 2019-06-05

1 answers

Is not going to suit you, but here at the company we also use TV panels that display information that is captured directly from the database in real time, and to be able to carry out this type of update I used the following:

<script type="text/javascript">
  function Ajax() {
    var $http, $self = arguments.callee;

    if (window.XMLHttpRequest) {
      $http = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
      try {
        $http = new ActiveXObject('Msxml2.XMLHTTP');
      } catch(e) {
        $http = new ActiveXObject('Microsoft.XMLHTTP');
      }
    }

    if ($http) {
      $http.onreadystatechange = function() {
        if (/4|^complete$/.test($http.readyState)) {
          document.getElementById('SuaDivQueIraAtualizar').innerHTML = $http.responseText;
          setTimeout(function(){$self();}, 3000);
        }
      };
      $http.open('GET', 'index.php' + '?' + new Date().getTime(), true);
      $http.send(null);
    }
  }
</script>

<script type="text/javascript">setTimeout(function() {Ajax();}, 3000);</script>

Note: this script is in the HEAD

You just Alt the text Yourqueiraupdate to the TAG you want to update in the dashboard, an example of this would be, just below the <body> you add a <div id="Geral"> naming it the way you want, in my case I put General so that way just change the name Suadivqueiraupdate to General

 0
Author: Roberto Valentim, 2019-06-05 20:47:17