Select and display data from a position in the database table

1

I need to create two tables on the same page where the first one will have only one client, in the case the first one in the list and the second one the other clients, the problem is that when the second table is ready, the first client also appears, and I need the second table to list itself from the second client, because when the client of the first one is serviced the page reloads and the first one from the bottom rises, so on.

What I've tried:

<?php
session_start();
require 'conexao.php';
$conexao = conexao::getInstance();
    $sql = 'SELECT id_agenda, hr_agendamento ,nome_cliente ,realizado FROM agenda
    WHERE nome_cliente = "nome_cliente "   and realizado ="N"  
     limit 1
    ';
    $stm = $conexao->prepare($sql);
    $stm->execute();
    $clientes = $stm->fetchAll(PDO::FETCH_OBJ);
$conexao2 = conexao::getInstance();
    $sql = 'SELECT id_agenda, hr_agendamento ,nome_cliente ,realizado FROM agenda
    WHERE nome_cliente = "nome_cliente "   and realizado ="N"  
     limit 3
    ';
    $stm = $conexao2->prepare($sql);
    $stm->execute();
    $clientes2 = $stm->fetchAll(PDO::FETCH_OBJ);

?>

How the tables are getting:

TABELA1
ID HORARIO CLIENTE REALIZADO
1  07:00    MARIA   NAO
TABELA2
ID HORARIO CLIENTE REALIZADO
1  07:00    MARIA   NAO
2  07:00    JOAO    NAO
3  07:00    CARLOS  NAO
    
asked by anonymous 03.09.2017 / 12:08

1 answer

1

You can use LIMIT to do this kind of thing too, here's how the query would look:

$sql = 'SELECT id_agenda, hr_agendamento, nome_cliente, realizado FROM agenda WHERE nome_cliente="nome_cliente" AND realizado="N" LIMIT 1, 3';
  • What does LIMIT 1, 3 mean?

The query will select from element 1 (starts from 0) and display at most 3 elements.

And OFFSET also works the same way:

$sql = 'SELECT id_agenda, hr_agendamento, nome_cliente, realizado FROM agenda WHERE nome_cliente="nome_cliente" AND realizado="N" LIMIT 3 OFFSET 1';

Note: I took the query from your question to base it on, but possibly it is wrong, that you are comparing a column with the string "client_name" and not with variables.

Here's what a comparison with a variable looks like:

$sql = "SELECT id_agenda, hr_agendamento, nome_cliente, realizado FROM agenda WHERE nome_cliente='$nome_cliente' AND realizado='N' LIMIT 1, 3";

And if the variable is coming in the post method:

$sql = "SELECT id_agenda, hr_agendamento, nome_cliente, realizado FROM agenda WHERE nome_cliente='{$_POST['nome_cliente']}' AND realizado='N' LIMIT 1, 3";
    
03.09.2017 / 16:00