Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7991793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:23:35+00:00 2026-06-04T13:23:35+00:00

I basically have this program which fetches orders from a database. My problem is

  • 0

I basically have this program which fetches orders from a database. My problem is I need to make a report in such a way that the script will get rows with the same column value then count them and display them.

Say Table ‘orders’

salesorder family product
1111111    pi_gx  af000
1111111    pi_gx  af000
1111112    sfng   af111
1111113    pi_gx  af000

will display in my php page

sales order   family  qty   product
1111111       pi_gx   2     af000
1111112       sfng    1     af111
1111113       pi_gx   1     af000

It counts the quantity of row of the said sales order and displays the quantity, at the same time displays only a single copy of that sales order in my page.

Here’s the code:

<body class="printable"><h1 align="center">New Orders Dropped for Product Integration 1X</h1>
<table align="center" width="100%">
<tr>
    <td class="labels">Prepared: </td>
<td class="boxed"><?php date_default_timezone_set("Asia/Singapore");$today = date("d/m/y H:i");echo $today; ?></td>
    <td class="divider">&nbsp;</td>
    <td class="labels">Time Coverage:  </td>
    <td class="boxed">12:00 to 2:00</td>
    <td class="divider">&nbsp;</td>
    <td class="labels">BirthStamp: </td>
    <td class="boxed">5/21/2012</td>
    <td class="divider">&nbsp;</td>
    <td class="labels">Saved: </td>
    <td class="boxed"><?php echo $today; ?></td>
</tr>
<tr>
    <td class="labels">Prepared by (Production): </td>
    <td><input type="text" name="preparer" id="preparer" class="boxedPrepared" /></td>
    <td class="divider"></td>
    <td class="labels">Recorded by (Store): </td>
    <td><input type="text" name="recorder" id="recorded" class="boxedPrepared" /></td>
    <td class="divider"></td>
    <td class="labels">Recorded: </td>
    <td class="boxed" colspan="3"><?php echo $today; ?></td>
</tr>
</table>
<br />
<?php
    $conn = mysql_connect("localhost", "root", "123456") or die(mysql_error()); 
    mysql_select_db("store") or die(mysql_error());
    $sql = mysql_query("SELECT * FROM report ORDER BY salesorder AND masterproduct ASC") or die(mysql_error());

    if(mysql_num_rows($sql) == 0) {
    echo "<center><b>No ORDER/S in Queue</b></center>";
} else {
    echo "
    <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\" class=\"data\">
              <tr>
                <td class=\"dataHeader\">Sales Order</td>
                <td class=\"dataHeader\">Sales Order Code</td>
                <td class=\"dataHeader\">Family</td>
                <td class=\"dataHeader\">Product Code</td>
                <td class=\"dataHeader\">Quantity</td>
                <td class=\"dataHeader\">Birth Stamp</td>
                <td class=\"dataHeader\">Due Date</td>
              </tr>
    ";
    while($result = mysql_fetch_array($sql)) {
        echo "
              <tr>
                <td class=\"data\">".$result['salesorder']."</td>
                <td class=\"data\"><span class=\"title\">*".$result['salesorder']."*</span><br />".$result['salesorder']."</td>
                <td class=\"data\">".$result['family']."</td>
                <td class=\"data\"><span class=\"title\">*".$result['masterproduct']."*</span><br />".$result['masterproduct']."</td>
                <td class=\"data\">";
                //need to echo the value here                   
                echo "</td>
                <td class=\"data\">".$result['birthstamp']."</td>
                <td class=\"data\"><span class=\"title\">*".$result['duedate']."*</span><br />".$result['duedate']."</td>
              </tr>

        ";  
    }
    echo "</table>";
}

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:23:37+00:00Added an answer on June 4, 2026 at 1:23 pm
    SELECT salesorder, family, product, COUNT() AS qty FROM orders 
           GROUP BY salesorder;
    

    EDIT: OK, try this on for size:

    SELECT r.*, t.qty FROM report r LEFT JOIN
          (SELECT salesorder, COUNT() AS qty FROM orders 
             GROUP BY salesorder) t
          ON t.salesorder=r.salesorder
        ORDER BY r.salesorder AND r.masterproduct ASC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a program which is goin to basically load news articles from
I have this error that is keeping me from moving forward. I basically have
Basically I have this string for example $str = 'По, своей 12' I need
Basically I have this string $str=word1 word2 word3; I need array( 'word1', 'word2', 'word3'
I have this script which basically toggles a bgColor class on and off so
I have a python program which takes input from stdin. Now, I've to write
Hoping someone can shed some light on this. I have a PHP program which
I have a third party program which basically allows users to send email and
Here's the thing... I have 2 GUI programs. A Menu Program,which is basically a
Well, i have this program i need to run via either functions however it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.