How to show only records with an associated character or letter to limit the search?

Asked

Viewed 43 times

0

The code below shows the records that include the initial number that was entered up to the limit of 5 (1, 11, 19, 107, 115...). Since the field to be searched has articles numbered with the word "Article" as default (Article 107 -, Article 107a -, etc.), how to show only the records with the number typed, for example 107, and also those with a capital letter, keeping the limit of 5 (example: Article 107 -, Article 107a -, Article 107b -, Article 107c -, Article 107d)???

<?php 
include 'conn.php';

$letter = $_GET["letter"];

$sql = "SELECT id,palavra from interpretacao_cpp where pronta != 0 AND palavra LIKE '".$letter."%' ORDER BY id asc limit 5" ;

$result = $conn->query($sql);

$sql2 = "SELECT DISTINCT(SUBSTR(`palavra`, 1, 1)) As abc from interpretacao_cpp where pronta != 0 ORDER BY abc";

$result2 = $conn->query($sql2);

?>
  • All records already have the word "article" as default?

  • Yeah, all the records have the word "article". Either there is only the number with the word Article, for example Article 107 -, or there may be one or more directly related numbers that have the word Article and its capital letter in sequence (A, B, C...), for example Article 107a -, Article 107b -, etc. In order to have one of the capital letters in a register and its sequence must first exist only the main article or number (without any letter), and therefore the sequence is always Article 107 -, Article 107a -, Article 107b -, ... etc.

  • The question was not understood but implied that if the user type 107 then he gets 107.º -, Artigo 107.º-A -, Artigo 107.º-B -, ... etc. If it is in the first consultation change the clause LIKE '".$letter."%' by `LIKE '%". $Letter."%' .

  • If you use this - LIKE '%".$letter."%' - dá erro de unespected t_sting reportado à linha 12 em: $sql2 = "SELECT DISTINCT(SUBSTR(`, 1, 1)) As abc from dicionario_penal Where pronto != 0 ORDER BY abc";

No answers

Browser other questions tagged

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