SQL to count the characters of a field if it is less than 10

Asked

Viewed 1,420 times

2

I am in great difficulty. I have the following SQL:

$contardescricao  = "0";       
$sqlxmldescricao  = "select id from imoveis where cod = '$cliente' 
                     AND (character_length(descricao)<'10')";
$rsqlxmldescricao = mysql_query($sqlxmldescricao) or die ("Banco XML não abre!");

while($rowxmldescricao = mysql_fetch_array($rsqlxmldescricao))
{
   $contardescricao = $contardescricao + 1;
}  

I’m trying to get her to check the field descrição has less than 10 characters.

My interest is to ride inside the sql structure this search to count the field DESCRIPTION of each record.

It is possible?

  • 2

    What’s the problem? Remember that character checking is done on top of a record just because of the cod = '$cliente'

  • @rray understand, but this script does not accurately display how many records there are in the table that have the DESCRICAO field with less than 10 characters. I wanted to make this resource within the SQL structure.

  • 2

    When you remove cod = '$cliente' and just leave: select id from imoveis where character_length(descricao < '10') comes true?

  • @Nothing, it doesn’t work!

  • 2

    Does not come any record? tested directly in the database? There is a syntax error ... that passed, the right is: select id from imoveis where character_length(descricao) < 10

  • 1

    @rray worked, it was lack of I run straight into the bank. Thank you very much!

  • Creates a response with the details of adapted code.

Show 2 more comments

1 answer

1


the correct would be

select id from imoveis where character_length(descricao) < 10

Browser other questions tagged

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