Error picking a select result

Asked

Viewed 48 times

0

Can someone help me with this code.

Makes that mistake:

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;

2 answers

0

friend, I think you missed renaming the table to the alias that you are using "pvi"

FROM ped_vendas_item.pvi **as pvi**
  • Thank you for answering. That really was the problem. But the concept of my code is not meeting me. Thank you anyway.

0

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

What I need is that if on some line, the Remaining volume is greater than zero and less than Total volume, status be 'P'.

And if all the lines of Remaining volume are equal to zero, then status = ’T'.

And if all the lines of Remaining volume are equal to Total volume, then status = 'N'.

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

Below list of products for delivery.

inserir a descrição da imagem aqui

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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.