place html inside php code the right way and that works

Tags: php html
Question!

i am trying to make html works and the right way to place it so it works placing html inside php code

<?php echo <td class=\"network\">".$show."</td>;?>


Answers

This does not give the impression that you've really tried much, or researched the issue.

<?php echo "<td class=\"network\">".$show."</td>";?>

^^ Should work to output HTML tags. (Though invalid as td should exist inside tables.)

Also note you can use different quotes to reduce the need for escaping. E.g.

<?php echo '<td class="network">'.$show.'</td>';?>


The default way to avoid double counting is to use SUM(DISTINCT expr).

This does not always work well enough, as you do not want to sum distinct values, but want to sum distinct rows even when those rows share the same values.

The solution is to use a sub-query to sum the details on order number and then join the result. Then you have only one total per order id to join with the order lines:

SELECT PurchaseOrderHeader.VendorID, 
  SUM(PurchaseOrderHeader.TotalDue) AS "TotalPay IN 2011", 
  SUM(POD.Qty) AS "TotalOrder IN 2011"
FROM PurchaseOrderHeader 
LEFT JOIN (
    SELECT PurchaseOrderDetail.PurchaseOrderID, SUM(OrderQty) AS Qty
    FROM PurchaseOrderDetail 
    GROUP BY PurchaseOrderDetail.PurchaseOrderID
   ) AS POD on PurchaseOrderHeader.PurchaseOrderID = POD.PurchaseOrderID
WHERE Datename(year,PurchaseOrderHeader.OrderDate) = 2011 
GROUP BY PurchaseOrderHeader.VendorID
ORDER BY VendorID

Also I took the freedom to remove the CASE WHEN statement from the SUM() to the WHERE part of the query. In this case that should give you the same results with shorter code.

By : Matijs


select  h.VendorID,
        SUM(CASE WHEN Datename(year,h.OrderDate) = 2011 THEN h.TotalDue else 0 END) as "TotalPay IN 2011", 
        SUM(CASE WHEN Datename(year,h.OrderDate) = 2011 THEN d.OrderQty else 0 END) as "TotalOrder IN 2011"
from    PurchaseOrderHeader h
left    join (
        select  t.PurchaseOrderID,
                sum(t.OrderQty) as OrderQty
        from    PurchaseOrderDetail t
        group   by t.PurchaseOrderID
        ) d on d.PurchaseOrderID = h.PurchaseOrderID
group by h.VendorID
order by VendorID
By : CodeArhat


This video can help you solving your question :)
By: admin