1
I loop a query. I check if the value of each record contains within any string (in the case $message). The problem is that when the value is found, in this case within the ELSE, while is closed for some reason. I need verification to continue to be done on all records, until the end of records.
$query = "select id, id_usuario texto from palavra";
$result = mysql_query($query);
while($palavras = mysql_fetch_array($result)) {
$valor = $palavras["texto"];
$iduser = $palavras["id_usuario"];
if(!strpos(strtolower($mensagem), strtolower($valor))) {
echo " não.<BR>";
} else {
echo " sim.<BR>";
$query = "select nome from usuario where id = $iduser";
$result = mysql_query($query);
$user_dados = mysql_fetch_row($result);
}
}
If I take the internal consultation, the loop remains normal as expected. But I need the query.
Your code seems to have a problem but it does not terminate while, what is the real code of Else? the ideal is to use operator
===
to make the comparison– rray
@rray I tested here and this way the loop remains normal. I will edit the code, the "Else" has more things...
– Daniel Accorsi
I understood now haha xD to break a loop use the
break
– rray
@rray You were right, the idea is to keep going, and not stop the loop. I tidied up there.
– Daniel Accorsi
Tbm I will change my answer ...
– rray
Calm down, you have hit the code but the text of the question not with the last comments, can edit the question and clarify.
– rray
The loop must continue, and not stop after finding the first occurrence.
– Daniel Accorsi
Okay, the show goes on :D
– rray
place:
$result = mysql_query($query) or die(mysql_error())
must have an error in the second query and in the while because of the reuse of$result
– rray
@rray vc killed the puzzle! $result reuse is in trouble. Internal query changed to $result2 and it worked, the loop continued.
– Daniel Accorsi
It’s like you haven’t read or tried what I went through in my answer
ini_set
and theerror_reporting
would have gotten to the problem, because as I said in the replyprovavelmente é algum erro no uso de mysql_fetch_array ou na sua query ou outra coisa próxima a isto
.– Guilherme Nascimento
@Guilhermenascimento I used his commands to show the error. Did not return any error. It was not a matter of error or syntax, but of programming, basically overwriting the $result variable. Thank you.
– Daniel Accorsi
@Danielaccorsi ok got it =)
– Guilherme Nascimento