1
I’m trying to make a SELECT
using MySQLi
and PREPARE
in a FOR
but not working. Always returning a single zero.
Application Code:
if( $teste = $mysqli->prepare("SELECT COUNT(*) AS TOTAL_CONTATOS, `data` AS DATA_CONTATO FROM `contatos` WHERE `data` >=? AND `data` <=?") )
{
$mes = date("m");
$ano = date("Y");
$data_start = "01-".$mes."-".$ano;
$tempo_start = strtotime($data_start);
$tempo_end = strtotime("+1 month", $tempo_start);
for( $i = $tempo_start; $i < $tempo_end; $i += 86400 )
{
$teste->bind_param( 'ss', date('Y-m-d', $i), date('Y-m-d', $tempo_end) );
$teste->execute();
$teste->bind_result( $totalcontato, $data_contato);
$teste->store_result();
}
while( $teste->fetch() )
{
echo $totalcontato ." | ". $data_contato;
echo "<br>";
}
}
@Bacco It was to return every day of the month with the values. Even if the value is 0.
– MoisesGama
what’s in your $test variable? try removing it and see what the result is...
– RFL
Throw the while into the for, it should be something different
– rray
@rray Printed some data. Thank you, with this I made some changes and got as I wanted. I will answer the question.
– MoisesGama
Nice that you managed to solve :D. Just for the record, I hate
bind_result()
– rray
@rray you use what in the place or not
PREPARE
? 'Cause, look it’s really boring, it has to be worth the performance.– MoisesGama
When possible use
get_result()
see the difference, but you need to stay smartget_result()
depedende mysqlnd, if it is not installed on your production host, only thebind_result()
even.– rray