Create a temporary file of select to repeat on other pages

0

Is it possible to do only a select query processing in php and mysql and use the result in pages that are continuations?

Exemplo:
Pagina 1 = faz select de dados, mostra o resultado e reserva.
Pagina 1-1 = mostra o reservado
Pagina 1-2 = mostra o reservado
Pagina 1-3 = mostra o reservado 
    
asked by anonymous 18.10.2017 / 13:14

1 answer

1

Following a basic logic, we make SQL and return a json

// PHP
$retorno = array();
$sql = $pdo->prepare("SELECT * FROM tabela");
$sql->execute();
$retorno['dados'] = $sql->fetchAll();

die(json_encode($retorno));

Once we've recovered the json , we'd have something similar to that.

[
  {
    "Nome": "Rafael Augusto"
  },
  {
    "Nome": "Geo"
  }
]

Now we could store the result in sessionStorage to recover on each page.

sessionStorage.setItem('retorno', JSON.stringify(retornoPHP))

Following more or less this logic, you have your feedback and can access it from any page. Of course there are other ways to do it, but I'm giving that example.

    
18.10.2017 / 14:31