Making my table display even if value is zero.

I have a page with a table that shows recieved/shipped/remaining progress of orders. the thing is, when the order hasn’t shipped anything yet(nothing in shipping.ponumber matching orders.ponumber, the table displays nothing. If it hasnt shipped anything I still want the order to appear,just with zero in the shipped field and however many to ship in the remaining field. I hope i explained myself well enough. Ive been trying alot of different things but just cant get it right. here is the code…

[php]<?php
$result = mysql_query(“SELECT orders.ID, two_ply, three_ply, ordered_by, ponumber, end_shipping, SUM(twoply) AS twoply, SUM(threeply) AS threeply
FROM orders JOIN shipping USING(ponumber)
GROUP BY ponumber”) or die( mysql_error());

$orderprogress="

"; echo $orderprogress;

while($row = mysql_fetch_array($result))
{

echo “

”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;

}
echo “

Order ID 2ply Ordered 2ply Shipped 2ply Remaining 3ply Ordered 3ply Shipped 3ply Remaining Ordered By PO Number Ship by Date
” . $row[‘ID’] . “” . ‘’ . $row[‘two_ply’] . ‘’ . “” . ‘’ . $row[‘twoply’] . ‘’ . “” . ‘’ . ($row[‘two_ply’]-$row[‘twoply’]) . ‘’ . “” . ‘’ . $row[‘three_ply’] . ‘’ . “” . ‘’ . $row[‘threeply’] . ‘’ . “” . ‘’ . ($row[‘three_ply’]-$row[‘threeply’]) . ‘’ . “” . $row[‘ordered_by’] . “” . $row[‘ponumber’] . “” . $row[‘end_shipping’] . “
”;

mysql_close();
?>[/php]

See if this is what you are looking for:SELECT orders.ID, two_ply, three_ply, ordered_by, ponumber, end_shipping, SUM(twoply) AS twoply, SUM(threeply) AS threeply FROM orders LEFT JOIN shipping USING(ponumber) GROUP BY ponumber

That did it. Thanks malasho. I guess i need to read a little more on the different JOINs.

Glad it worked for you. I find that I hardly every use anything other than Join and Left Join, but it’s good to know everything that is available for those times that you need something different!

Best,

jay

Sponsor our Newsletter | Privacy Policy | Terms of Service