I find the following problem:
I have an array called $data2
and when making a query sql
the result of it can be searched in the array, I'm working with checkbox
so if the result of the query sql
is in the array $data2
this prints a checked
. This is the code I'm working on:
while($row=mysqli_fetch_array($query)){
// CADENA DE TEXTO A COMPARAR
$nombre_ids = $row[2].','.$row[1].','.$row[0];
// CICLO APRA RECORRER EL ARRAY
for($i=0;$i<count($data2);$i++){
// COMPARAR SI EXISTE LA CADENA SQL EN EL ARRAY
if($data2[$i]==$nombre_ids){
$mensaje .= '
<tr style="background-color:#FF7575;">
<td>
<input type="checkbox" class="check" name="'.$row[0].'" id="'.$nombre_ids.'" checked>
<label for="'.$nombre_ids.'">'.$row[2].'</label>
</td>
</tr>';
} else{
$mensaje .= '
<tr>
<td>
<input type="checkbox" class="check" name="'.$row[0].'" id="'.$nombre_ids.'">
<label for="'.$nombre_ids.'">'.$row[2].'</label>
</td>
</tr>';
}
}
}
The problem is that I duplicate the query data depending on how much data I have in the array $data2