Search in php does not return results correctly [closed]

-1

I have a problem regarding the return of the information of the database in php, I have two tables, one tb_regiao, with the Brazilian states and another, tb_representante with the representatives in each state.

Below is the part with the select:

 <form class="ajs-form-representante" method="GET" action="pesquisar_representantes_art_ferro_moveis_fibra_sintetica.php">
            <select type="text" name="pesquisar" >
                <option class="lista-cidade" value="" selected="selected">Escolha a Região</option>
                <?php require_once ("ajs-script-php/selecta_cidade.php");?>
            </select>
            <input type="submit" value="BUSCAR">
        </form>

The script to select the region is this below:

<?php
require_once("ajs-adm/conexao/conecta.php");

$pesqu = $_GET["pesquisar"];
$listar = $conexao->prepare('SELECT * FROM tb_regiao WHERE regiao LIKE "%'.$pesqu.'%" LIMIT 27');
$listar->execute();
while ($exibe = $listar->fetch()){
    $nome_cidade = utf8_encode($exibe['regiao']);
    $nome_id = utf8_encode($exibe['id_id_reg']);
    echo "<option  class='$nome_id'>$nome_cidade</option>";
}

The page code to display the result is as below:

        <section class="ajs-section-rs-a">
            <?php
                $pesquisar = $_GET['pesquisar'];
                $result_repres = "SELECT * FROM tb_representante WHERE estado LIKE '%".$pesquisar."%' LIMIT 1";
                $result_resul_repres = mysqli_query($conect, $result_repres);
                   while($rows_repres = mysqli_fetch_array($result_resul_repres)){
                       echo "<p><b>Representante:</b> ".utf8_encode($rows_repres['nome_rp'])."</p>";
                       echo "<p><b>E-mail:</b> ".utf8_encode($rows_repres['email'])."</p>";
                       echo "<p><b>Celular:</b> ".utf8_encode($rows_repres['cel_a'])."</p>";
                       echo "<p><b>Celular:</b> ".utf8_encode($rows_repres['cel_b'])."</p>";
                       echo "<p><b>Telefone Fixo:</b> ".utf8_encode($rows_repres['tel_fixo'])."</p>";
                       echo "<p><b>Empresa:</b> ".utf8_encode($rows_repres['nome_empresa'])."</p>";
                       echo "<p><b>Endereço:</b> ".utf8_encode($rows_repres['rua'])."</p>";
                       echo "<p><b>Bairro:</b> ".utf8_encode($rows_repres['bairro'])."</p>";
                       echo "<p><b>Cidade:</b> ".utf8_encode($rows_repres['cidade'])."</p>";
                       echo "<p><b>Cep:</b> ".utf8_encode($rows_repres['cep'])."</p>";
                       echo "<p><b>Estado:</b> ".utf8_encode($rows_repres['estado'])."</p>";
                   }
            ?>
        </section>

Below is the tb_regiao table:

--

CREATE TABLE 'tb_regiao' (
  'id_reg' int(11) NOT NULL,
  'id_id_reg' varchar(2) COLLATE utf8_unicode_ci NOT NULL,
  'regiao' varchar(30) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Extraindo dados da tabela 'tb_regiao'
--

INSERT INTO 'tb_regiao' ('id_reg', 'id_id_reg', 'regiao') VALUES
(1, '1', 'Acre'),
(2, '2', 'Alagoas'),
(3, '3', 'Amapá'),
(4, '4', 'Amazonas'),
(5, '5', 'Bahia'),
(6, '6', 'Ceará'),
(7, '7', 'Distrito Federal'),
(8, '8', 'Espírito Santo'),
(9, '9', 'Goiás'),
(10, '10', 'Maranhão'),
(11, '11', 'Mato Grosso'),
(12, '12', 'Mato Grosso do Sul'),
(13, '13', 'Minas Gerais'),
(14, '14', 'Pará'),
(15, '15', 'Paraíba'),
(16, '16', 'Paraná'),
(17, '17', 'Pernambuco'),
(18, '18', 'Piauí'),
(19, '19', 'Rio de Janeiro'),
(20, '20', 'Rio Grande do Norte'),
(21, '21', 'Rio Grande do Sul'),
(22, '22', 'Rondônia'),
(23, '23', 'Roraima'),
(24, '24', 'Santa Catarina'),
(25, '25', 'São Paulo'),
(26, '26', 'Sergipe'),
(27, '27', 'Tocantins');

--
-- Indexes for dumped tables
--

--
-- Indexes for table 'tb_regiao'
--
ALTER TABLE 'tb_regiao'
  ADD PRIMARY KEY ('id_reg');

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table 'tb_regiao'
--
ALTER TABLE 'tb_regiao'
  MODIFY 'id_reg' int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28;COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

And below is the table tb_representante:

--

CREATE TABLE 'tb_representante' (
  'id' int(11) NOT NULL,
  'id_id_reg' varchar(2) COLLATE utf8_unicode_ci NOT NULL,
  'nome_rp' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  'email' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  'nome_one' varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  'nome_two' varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  'nome_three' varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  'nome_empresa' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  'tel_fixo' varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  'cel_a' varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  'cel_b' varchar(20) COLLATE utf8_unicode_ci NOT NULL,
  'rua' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  'bairro' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  'cidade' varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  'cep' varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  'estado' varchar(40) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Extraindo dados da tabela 'tb_representante'
--

INSERT INTO 'tb_representante' ('id', 'id_id_reg', 'nome_rp', 'email', 'nome_one', 'nome_two', 'nome_three', 'nome_empresa', 'tel_fixo', 'cel_a', 'cel_b', 'rua', 'bairro', 'cidade', 'cep', 'estado') VALUES
(1, '9', 'Alamo Manini Representações', '[email protected]', 'Elaine', 'Ataíde', 'Deivide', 'Alamo Manini Representações', '(62) 3515-1110', '(62) 99945-0318', '(62) 98252-1518', 'Rua 6, nº 370 Quadra E3, Lote 31, Sala 910', 'Empire Center, setor oeste', 'Goiânia', '74.115-070', 'Goiás'),
(2, '5', 'Caires Representações', '[email protected]', 'Edvando', 'Zilmz', '', 'Caires Representações', '(77) 3441-2728', '(77) 99997-7885', '(77) 99996-3581', 'Praça dr. Nelson Lula, nº 22', 'Centro', 'Brumado', '46100-000', 'Bahia');

--
-- Indexes for dumped tables
--

--
-- Indexes for table 'tb_representante'
--
ALTER TABLE 'tb_representante'
  ADD PRIMARY KEY ('id');

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table 'tb_representante'
--
ALTER TABLE 'tb_representante'
  MODIFY 'id' int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

When I click to fetch the result, only the second record is returned, it does not show the first record and no other record.

    
asked by anonymous 17.09.2017 / 17:19

1 answer

0

I found the error, with this hint of yours, in the script to select the region, I put class = '$ id_id', when you wrote above, 'put the value' I looked at and changed to 'value =' $ id ' ", and ready, it ran normal, anyone who wants to use the code just change that runs 100% '

this is the corrected script

<?php
require_once("ajs-adm/conexao/conecta.php");

$pesqu = $_GET["pesquisar"];
$listar = $conexao->prepare('SELECT * FROM tb_regiao WHERE regiao LIKE "%'.$pesqu.'%" LIMIT 27');
$listar->execute();
while ($exibe = $listar->fetch()){
    $nome_cidade = utf8_encode($exibe['regiao']);
    $nome_id = utf8_encode($exibe['id_id_reg']);
    echo "<option  value='$nome_id'>$nome_cidade</option>";
}
    
21.09.2017 / 20:49