0

我有来自两个不同表的数据,我将它们连接在一起并对其运行查询。

我想要实现的是,我的结果将根据订单号进行分组,并且可能还有其他条件——如果成功的话。

我正在尝试根据我们收到的库存损坏物品生成报价。

一个报价单可以包含多个工作记录 ID,只要订单号匹配并且这些订单号都是在同一天输入的。需要注意的是,如果其中一个工作记录碰巧有一个项目,我们必须将其发送给制造商以进行估算(这是我要引入的主数据库表中的一个标志。

不过现在,我想取回我得到的数据并将其显示在屏幕上,作为系统发送报价之前报价将包含的内容的预览。

我正在寻找的最终结果可以在我模拟的这张图片中找到:

想要的最终结果的样机

这是我的查询:

$sql = mysql_query("SELECT workRecord_details.orderNumber, workRecord_main.mfrEstimate, workRecord_main.id, workRecord_main.createdDate, workRecord_main.nameid, workRecord_details.dateEntered
                        FROM workRecord_main
                        INNER JOIN workRecord_details ON workRecord_main.id = workRecord_details.workRecordId
                        WHERE workRecord_main.billable = '1' AND workRecord_main.STATUS = '2' AND workRecord_details.dateEntered LIKE '2013-08-14%' ORDER BY workRecord_details.orderNumber, workRecord_main.mfrEstimate, workRecord_main.id"
                    ) or die("Can't execute: " . mysql_error());

if(mysql_num_rows($getWR) > 0){
$i = 0;
while($wrData = mysql_fetch_array($getWR))
    {
        $color_A = 'class="alt2"'; 
        $color_B = 'class="alt1"';

        $row_color = ($i % 2) ? $color_A : $color_B;        

        echo '<table width = "100%" cellspacing = "0" cellpadding = "0" border = "0">
                <tr>
                    <td class = "colheader">Work Record #</td>
                    <td class = "colheader">Company</td>
                    <td class = "colheader">Order #</td>
                    <td class = "colheader">Description</td>
                </tr>';

        echo '<tr>
                <td width= "100px" ' . $row_color . '>' . $wrData['id'] . '</td>
                <td width = "150px"' . $row_color . '>' . companyNameByNameID($wrData['nameid']) . '('.getKdaccount($wrData['nameid']).')</td>
                <td width = "100px"' . $row_color . '>' . $wrData['orderNumber'] . '</td>
                <td width = "600px"' . $row_color . '>' . $wrData['partNo'] . '</td>
            </tr>';

        echo '</table><br /><br />';


        $i++;
    }
}   
4

1 回答 1

1

要根据订单号创建表格,或发送到制造商标志,您需要跟踪最后使用的订单号和/或标志。尝试这样的事情 -

$i = 0;
$current_orderNumber = ''; //variable to track current orderNumber
$color_A = 'class="alt2"'; 
$color_B = 'class="alt1"';
while($wrData = mysql_fetch_array($getWR))
{
     // Start a new table for each orderNumber or if send to mfr is set
 if($wrData['orderNumber'] != $current_orderNumber || isset(YOUR_SEND_TO_MFR_FLAG)){
        if($i!=0){  // if not the first table, close the last table
        echo '</table><br /><br />';
    }
            // start a new table
    echo '<table width = "100%" cellspacing = "0" cellpadding = "0" border = "0">
            <tr>
                <td class = "colheader">Work Record #</td>
                <td class = "colheader">Company</td>
                <td class = "colheader">Order #</td>
                <td class = "colheader">Description</td>
            </tr>';
 $i=0; //reset the row # for the new table
 }
    $current_orderNumber = $wrData['orderNumber']; // set current orderNumber to this orderNumber

    $row_color = ($i % 2) ? $color_A : $color_B;        

    echo '<tr>
            <td width= "100px" ' . $row_color . '>' . $wrData['id'] . '</td>
            <td width = "150px"' . $row_color . '>' . $wrData['nameid'] .'</td>
            <td width = "100px"' . $row_color . '>' . $wrData['orderNumber'] . '</td>
            <td width = "600px"' . $row_color . '>' . $wrData['partNo'] . '</td>
        </tr>';

    $i++;
}
echo '</table><br /><br />'; // close the last table.

phpFiddle 示例 - http://phpfiddle.org/main/code/7kx-qgw

于 2013-08-16T19:43:34.687 回答