Jump to content

How Do I Do This


Recommended Posts

how do i design a layout as below : -

 

Item  Description  Serial Number  Qty      Unit Price  Amount(RM)

1.  ABC                          3956, 3957  2  8.00      16.00

2.  ABD                      4235, 4236, 4237,      18          16.00    288.00

                                                4238, 4239, 4240,

                                                4241, 4242, 4243,

                                                4244, 4245, 4246,

                                                4247, 4248, 4249,

                                                4251, 4253, 4254   

                                                                                                total    254.00

                                                                              commission 10%      25.40

                                                                                      Grand Total    229.60

 

 

I have already done a part of the php script just lack how to fit  unit price and amount in the coding.

Below is the script that i have done, please help me to modify the script to design the layout as above. please advise.Thanks a lot.

 

$count = 1;

 

$result3 = mysql_query("SELECT package, serialNo FROM orderdetail WHERE resellerID = '$resellerID' AND orderNo='$orderNo' ORDER BY package, serialNo");

                $data = array();

 

                // build array of serial numbers for each package

                while (list($p, $s) = mysql_fetch_row($result3))

  {

              $data[$p][]= $s;

                }

 

                echo "<TABLE WIDTH='100%' BORDER ='1'>";

  echo "<TR>";

  echo "<TD WIDTH='10%' ALIGN='center'><FONT CLASS = 'View'><B>Item</B></FONT></TD>

            <TD WIDTH='30%' ALIGN='center'><FONT CLASS = 'View'><B>Description</B></FONT></TD>

            <TD WIDTH='10%' ALIGN='center'><FONT CLASS = 'View'><B>Quantity</B></FONT></TD>

            <TD WIDTH='50%' ALIGN='center'><FONT CLASS = 'View'><B>Serial</B></FONT></TD>";

 

                foreach($data as $pkg => $s_array)

  {

                        $num = count($s_array);

            $gserial = listSerNums($s_array,0);

 

            echo "<TR valign='top'>

          <TD><FONT CLASS='normalText'>$count</FONT></TD>

                        <TD><FONT CLASS='normalText'>$pkg</FONT></TD>

          <TD><FONT CLASS='normalText'>$num</FONT></TD>

                        <TD><FONT CLASS='normalText'>" . listSerNums($s_array, 6) . "</FONT></TD>

                    </TR>";

            $count++;

                }

 

            echo "</TABLE>";

 

          function listSerNums($sers, $n)

          {

                                $i = 1;

      $j = 1;

      $x = count($sers);

                                foreach ($sers as $s)

      {

                  if ($j++ == $x)

                {

                        $res .= $s;

                }

                else

                {

                                                  $res .= $s . ', ';

                }

                if ($n != 0)

                {

        if ($i++ % $n == 0) $res .= '

';

                }

                                }

                                return $res;

                        }

 

Link to comment
Share on other sites

Don't know what your tables are like so I set up this

 

Test data

CREATE TABLE orderdetail (
    item int,
    descrip varchar(20),
    sno int,
    price decimal(8,2)
);

INSERT INTO orderdetail VALUES
(1, 'ABC', 3956, 8.00),
(1, 'ABC', 3957, 8.00),
(2, 'ABD', 4235, 16.00),
(2, 'ABD', 4236, 16.00),
(2, 'ABD', 4237, 16.00),
(2, 'ABD', 4238, 16.00),
(2, 'ABD', 4239, 16.00),
(2, 'ABD', 4241, 16.00),
(2, 'ABD', 4242, 16.00),
(2, 'ABD', 4243, 16.00),
(2, 'ABD', 4244, 16.00),
(2, 'ABD', 4245, 16.00),
(2, 'ABD', 4246, 16.00),
(2, 'ABD', 4247, 16.00),
(2, 'ABD', 4248, 16.00);

 

Process

<?php
include '../test/db2.php';  //connect stuff

$sql = "SELECT o.item, o.descrip, o.price,
        GROUP_CONCAT(o.sno ORDER BY o.sno SEPARATOR ', ') as sernums,
        COUNT(*) as qty,
        (COUNT(*) * price) as total
        FROM orderdetail o
        GROUP BY o.item, o.descrip, o.price";
$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");

echo "<table cellpadding='5' width='520'>" ;
echo "<tr valign='top'><td>Item</td><td>Description</td><td colwidth='50%'>Serial Nos</td><td>Qty</td><td>Unit<br>price</td><td>Total</td></tr>";
$total = 0;
while (list($i, $d, $p, $s, $q, $t) = mysql_fetch_row($res)) {
    echo "<tr valign='top''><td>$i</td><td>$d</td><td colwidth='50%'>$s</td><td>$q</td><td>$p</td><td>$t</td></tr>";
    $total += $t;
}
printf ("<tr><td colspan='5'>Total</td><td>%.2f</td></tr>", $total);
printf ("<tr><td colspan='5'>Commission 10%%</td><td>%.2f</td></tr>", $total*0.1);
printf ("<tr><td colspan='5'>Grand Total</td><td>%.2f</td></tr>", $total*1.1);
echo '</table>';
?>

 

-->

[pre]

Item  Description Serial Nos          Qty        Unit      Total

                                                  price

1    ABC        3956, 3957            2        8.00      16.00

2    ABD        4235, 4236, 4237,    13        16.00      208.00

                  4238, 4239, 4241,

                  4242, 4243, 4244,

                  4245, 4246, 4247,

                  4248 

Total                                                        224.00

Commission 10%                                                22.40

Grand Total                                                  246.40

[/pre]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.