Error fetching the result of a select

0

Someone can help me with this code.

Give this error:

Warning: mysql_fetch_array () expects parameter 1 to be resource, boolean given in /var/www/xxx/teste.php on line 14

Notice: Undefined variable: status in /var/www/santa/teste2.php on line 23

include "mysql.php";  
$ped_venda_id = 13;


$sql = mysql_query ("SELECT pvi.ped_venda_id, IF(pvi.volume_restante ==0, 'T', IF(pvi.volume_total == pvi.volume_restante, 'N', 'P')) as 'status' FROM ped_vendas_item.pvi  WHERE ped_venda_id = '$ped_venda_id' ");  


while($r = mysql_fetch_array($sql)){ 

    $status = $r['status'];

}

echo $status;
    
asked by anonymous 20.09.2018 / 14:58

2 answers

0

My friend, I think you've missed your table renaming for the alias you're using "pvi"

FROM ped_vendas_item.pvi **as pvi**
    
20.09.2018 / 15:37
0

In this code, the return is based only on the first item in the list.

What I need is if in some line, Volume_Restante is greater than zero and less than Volume_Total , status is 'P'.

And if all rows of ReString equal zero, then status = 'T'.

And if all the lines in ReSound are equal to Volume_Total , then status = 'N'.

But in this case, he saw the first line that the volume_start was zero, and played in status 'T', ignoring the other line that has value 1.

Below list of products for delivery.

include"topop.php";
include "mysql.php";

$ped_venda_id = 13;


$sql = mysql_query ("SELECT pvi.ped_venda_id, IF(pvi.volume_restante = 0, 'T', IF(pvi.volume_total = pvi.volume_restante, 'N', 'P')) as 'status' FROM ped_vendas_item as pvi  WHERE ped_venda_id = '$ped_venda_id' ") or die(mysql_error());  


while($r = mysql_fetch_array($sql)){ 

    $status = $r['status'];

}

echo $status;
    
20.09.2018 / 16:17