Bug #80740 [Com]: Possible "in_array" bug

From: Date: Fri, 12 Feb 2021 20:27:33 +0000
Subject: Bug #80740 [Com]: Possible "in_array" bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232112@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80740&edit=1

 ID:                 80740
 Comment by:         celestinoxp at hotmail dot com
 Reported by:        celestinoxp at hotmail dot com
 Summary:            Possible "in_array" bug
 Status:             Feedback
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Windows 10
 PHP Version:        8.0Git-2021-02-12 (snap)
 Block user comment: N
 Private report:     N

 New Comment:

I checked my code and I'm 99.9% sure that it's a PHP bug!


Previous Comments:
------------------------------------------------------------------------
[2021-02-12 16:32:05] celestinoxp at hotmail dot com

It's so hard the code? If you see, it should insert delays of numbers.
Its a lottery numbers (n1, n2, n3, n4, n5, ns) and delays of this numbers (n1_ausencias,
n2_ausencias)...

------------------------------------------------------------------------
[2021-02-12 16:12:04] danack@php.net

If nothing else, please make it clear what you think 'correct' values are. It takes too
long to figure out what you are implying the issue is from screenshots. But this will almost
certainly a bug in your code, rather than PHP.

------------------------------------------------------------------------
[2021-02-12 16:09:37] danack@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.



------------------------------------------------------------------------
[2021-02-12 16:07:33] celestinoxp at hotmail dot com

Description:
------------
I have a code to insert delays of numbers in a mysql table, however values are not correct.

I think my code is correct, so, assuming that, i think problem is in php or mysql, it´s for that
i need help to check if is a bug in php or not...


I have a mysql table with lotto numbers (n1, n2, n3...) and delays (n1_ausencias, n2_ausencias...)

my script is to update values (initial 0) to delay values in (n1_ausencias, n2_ausencias,
n3_ausencias...) 

printscreen: https://i.stack.imgur.com/GBZQx.png 

Test script:
---------------
<?php

	set_time_limit(0);

	include "../ligar_bd.php";
	
	$i = 0;
	
	$result = mysqli_query($db, "SELECT id, data, n1,
n2, n3, n4, n5, ns FROM
tbl_todos WHERE nome_do_jogo = 'totoloto' ORDER BY
tbl_todos.data DESC;");
	
	$f = mysqli_num_rows($result);
	
	while ($dados = mysqli_fetch_array($result)){
		
		$chave_bd = array($dados['n1'], $dados['n2'], $dados['n3'],
$dados['n4'], $dados['n5']);
		
		$conta = -1;
		
		++$i;
		
		$n1_encontrou = 0;
		$n2_encontrou = 0;
		$n3_encontrou = 0;
		$n4_encontrou = 0;
		$n5_encontrou = 0;
		$ns_encontrou = 0;
		
		$result2 = mysqli_query($db, "SELECT id, data, n1,
n2, n3, n4, n5, ns FROM
tbl_todos WHERE nome_do_jogo = 'totoloto' ORDER BY
tbl_todos.data DESC LIMIT $i, $f;");
		
		while ($dados2 = mysqli_fetch_array($result2)){	
			
			++$conta;
			
			$n1 = $dados2['n1'];
			$n2 = $dados2['n2'];
			$n3 = $dados2['n3'];
			$n4 = $dados2['n4'];
			$n5 = $dados2['n5'];
			$ns = $dados2['ns'];			
			
			if (in_array($n1, $chave_bd) and ($n1_encontrou == 0)){
				
				$n1_encontrou = 1;
				$n1_pos = $conta;
			}
			
			if (in_array($n2, $chave_bd) and ($n2_encontrou == 0)){
				
				$n2_encontrou = 1;
				$n2_pos = $conta;
			}
			
			if (in_array($n3, $chave_bd) and ($n3_encontrou == 0)){
			
				$n3_encontrou = 1;
				$n3_pos = $conta;
			}
			
			if (in_array($n4, $chave_bd) and ($n4_encontrou == 0)){
				
				$n4_encontrou = 1;
				$n4_pos = $conta;
			}
			
			if (in_array($n5, $chave_bd) and ($n5_encontrou == 0)){
				
				$n5_encontrou = 1;
				$n5_pos = $conta;
			}
			
			if ($ns == $dados['ns'] and $ns_encontrou == 0){
				
				$ns_encontrou = 1;
				$ns_pos = $conta;
			}
			
			//Se encontrou ausencias de todos, não precisa perder mais tempo a percorrer toda a tabela
			if ($n1_encontrou == 1 and $n2_encontrou == 1 and $n3_encontrou == 1 and $n4_encontrou == 1 and
$n5_encontrou == 1 and $ns_encontrou == 1){
				
				break;
			}
			
		} //fecha while dados2
		
		$atualiza = mysqli_query($db, "UPDATE tbl_todos SET n1_ausencias =
$n1_pos, n2_ausencias = $n2_pos, n3_ausencias = $n3_pos,
n4_ausencias = $n4_pos, n5_ausencias = $n5_pos, ns_ausencias
= $ns_pos WHERE tbl_todos.id = $dados[id];");			
		
		
	} //fecha while dados
	
?>

Expected result:
----------------
correct delay values

Actual result:
--------------
incorrect delay values

printscreen: https://i.stack.imgur.com/GBZQx.png


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80740&edit=1


Thread (15 messages)

« previous php.bugs (#232112) next »