I am trying to add the values of a row from bottom to top but I can not do it, I have tried with a for loop with the array_reverse property and with the ORDER BY property but I can not find the correct result. In the array_reverse I invert the values of the column but not the row as I pretend in the other cases does nothing. This is the code:
//código para hacer el conteo que funciona
$aColumns = array('numero_comprobante');
$sTable = "comprobante";
$sWhere = "";
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
$sWhere .= $aColumns[$i]." LIKE '%".$q."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
$sWhere.=" order by codigo desc";
// a partir de acá debería de empezar con el conteo por filas invertido
$sql1= "select * from comprobante where descripcion='".$descripcion."' order by codigo asc";
$query1 = mysqli_query($con, $sql1);
$fila = mysqli_num_rows($query1);
if ($fila==1) {
$cantidades=$cantidad;
}
else {
if ($id_tipo==3) {
$cantidades-=$cantidad;
}
if ($id_tipo==2) {
$input = array($cantidad, array($numero_comprobante));
$reversed = array_reverse($input);
print_r($reversed);
$cantidades+=$cantidad;
}
if ($id_tipo==1) {
$cantidades-=$cantidad;
}
}
Note: The $ id_type corresponds to purchase invoice, sales invoice or payment order. - The sum is only made when the descriptions match.