English 中文(简体)
条款太多?
原标题:Too many clauses?

我撰写了相当出色的字句,根据与其他领域相匹配的制约因素,把3个领域退回。 根据最后结果,委员会有3项成果,将回报结果2。

public function ListRoomTotals($room, $date, $dateTo = null) {

    // If dateTo hasn t been set, make it now

    if(!isset($dateTo) or $dateTo == "") {

        $dateTo = $date;

    }

    // Return an array with each bundle number and the quantity for each day

    $scanner = $this->GetScannerNumber($room);

    $sql = "SELECT * FROM `scanners` WHERE `Scanner` IN (";

        foreach($scanner as $x) {

            $sql .= $x . ",";

        }

    $sql .= "0)

            AND `Date` BETWEEN  " . $date . "  AND  " . $dateTo . " 

            GROUP BY `KordNo`, `BundleNumber`;";

    $result = mysql_query($sql);

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

        $sql = "SELECT `BundleReference`, `QtyIssued`, `WorksOrder`,

                FROM `ArchiveBundle`

                WHERE `KordNo` =  " . $row[ KordNo ] . " 

                AND `BundleNumber` =  " . $row[ BundleNumber ] . " ;";

        $result2 = mysql_query($sql);

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

        $sql = "SELECT `ArchiveBundle`.`QtyIssued`, `ArchiveBundle`.`WorksOrder`,

                        `ArchiveBundle`.`Colour`, `ArchiveBundle`.`Size`

                FROM `ArchiveBundle`

                WHERE `ArchiveBundle`.`KordNo` =  " . $x[ KordNo ] . "  AND

                  `ArchiveBundle`.`BundleNumber` =  " . $x[ BundleNumber ] . " ;";

        $result3 = mysql_query($sql);
                        $row = mysql_fetch_row($result3);   


           // Now we need to query what the product group is

        $sql = "SELECT `Stock`.`ProductGroup`

            FROM `Stock`, `TWOrder`

            WHERE `TWOrder`.`WorksOrderNumber` =  " . $row[1] . "  AND

                `TWOrder`.`Colour` =  " . $row[2] . "  AND

                `TWOrder`.`Size` =  " . $row[3] . "  AND

                `Stock`.`ProductCode` = `TWOrder`.`Product`;";



        $result4 = mysql_query($sql);

        $row2 = mysql_fetch_row($result4);

        if(in_array($row2[0], array(50, 100, 150, 300 , 350 , 925 ,930, 940)))

        {


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

            if($row[0] != "") {

                $final[] = $row;

            } else {

                $final[] = array("Can t find bundle number", "N/A");

            }

        }

    }

    return $final;

   }

我可以在以下一页使用这一功能。

 $result = $scanner->ListRoomTotals($_GET[ room ], $_GET[ date ]);

            $total = 0;

            foreach($result as $x) {

                $content .= "<tr>

                    <td>" . $x[0] . "</td>

                    <td>" . $x[1] . "</td>

                </tr>";
                                    $total += $x[1];

            }

            $weeklyTotal += $total;

            $content .= "<tr><td>Total Pairage:</td><td>" . $total . "                    </td></tr>

                    <tr><td>Total Dozens:</td><td>" .      number_format($total/12,2) . "</td></tr></table>

        </td>

我知道,它可能写得很坏,因为它是没有正确归还的主要原因。 是否有任何人可能建议分裂。 我很粗略地讲,在php上,我对它的理解很差。 谢谢。

问题回答

如果你的代码被删除,我做了一些小改动。 我的建议是将职能清单格式细分为较小的职能。 例如,可以将Scanners移至自己的功能中。 因此,你不以结果为由放弃这一职能,而是将每个分任务分成一个较小的职能。 您也询问了您的当选。 如果你只需要两个或三个领域,这也是一个绩效问题。 你也可以回答你提出的问题。

public function ListRoomTotals($room, $date, $dateTo = null) {
    // If dateTo hasn t been set, make it now
    if(!isset($dateTo) || $dateTo == "") { //<-- Replaced or with ||
        $dateTo = $date;
    }

    // Return an array with each bundle number 以及 the quantity for each day
    $scanner = $this->GetScannerNumber($room);
    $sql = "SELECT * FROM `scanners` WHERE `Scanner` IN (".implode( , , $scanner);

    // replace foreach loop with implode
    //foreach($scanner as $x) {
    //  $sql .= $x . ",";
    //}

    $sql .= "0)
    AND `Date` BETWEEN  " . $date . "  AND  " . $dateTo . " 
    GROUP BY `KordNo`, `BundleNumber`;";

    $result = mysql_query($sql);

    while($row = mysql_fetch_array($result)) {
        $sql = "SELECT `BundleReference`, `QtyIssued`, `WorksOrder`,
        FROM `ArchiveBundle`
        WHERE `KordNo` =  " . $row[ KordNo ] . " 
        AND `BundleNumber` =  " . $row[ BundleNumber ] . " ;";

        $result2 = mysql_query($sql);

        while($row = mysql_fetch_array($result2)) {     
            $sql = "SELECT `ArchiveBundle`.`QtyIssued`, `ArchiveBundle`.`WorksOrder`,
            `ArchiveBundle`.`Colour`, `ArchiveBundle`.`Size`
            FROM `ArchiveBundle`
            WHERE `ArchiveBundle`.`KordNo` =  " . $x[ KordNo ] . "  AND
            `ArchiveBundle`.`BundleNumber` =  " . $x[ BundleNumber ] . " ;";

            $result3 = mysql_query($sql);
            $row     = mysql_fetch_row($result3);

            // Now we need to query what the product group is
            $sql = "SELECT `Stock`.`ProductGroup`
            FROM `Stock`, `TWOrder`
            WHERE `TWOrder`.`WorksOrderNumber` =  " . $row[1] . "  AND
            `TWOrder`.`Colour` =  " . $row[2] . "  AND
            `TWOrder`.`Size` =  " . $row[3] . "  AND
            `Stock`.`ProductCode` = `TWOrder`.`Product`;";

            $result4 = mysql_query($sql);
            $row2    = mysql_fetch_row($result4);

            if(in_array($row2[0], array(50, 100, 150, 300 , 350 , 925 ,930, 940))) {
                while($row = mysql_fetch_array($result2)) {
                    if($row[0] != "") {
                        $final[] = $row;
                    } else {
                        $final[] = array("Can t find bundle number", "N/A");
                    }
                }
            }
            return $final;
        }
    }
}

以及

$result = $scanner->ListRoomTotals($_GET[ room ], $_GET[ date ]);
    $total = 0;

    foreach($result as $x) {
        $content .= "<tr>
            <td>" . $x[0] . "</td>
            <td>" . $x[1] . "</td>
        </tr>";
        $total += $x[1];
    }
    $weeklyTotal += $total;
    $content .= "<tr><td>Total Pairage:</td><td>".$total."                    </td></tr>
            <tr><td>Total Dozens:</td><td>".number_format($total/12,2)."</td></tr></table>
</td>"; //<-- adding the closing double quote

最新资料:

无法确定:

$x[ KordNo ]
$x[ BundleNumber ]

页: 1

$row[ KordNo ]
$row[ BundleNumber ]

您的法典的编排格式使得人们难以看到什么进展。

清理后,似乎与你一样,进行了一系列的KQ查询,每个查询都取决于以前的询问。 利用联合网络进行单一查询,获取你想要的数据,将更有意义。

此外,请你提出两个问题。

 $sql = "SELECT `BundleReference`, `QtyIssued`, `WorksOrder`,
         FROM `ArchiveBundle`
         WHERE `KordNo` =  " . $row[ KordNo ] . " 
           AND `BundleNumber` =  " . $row[ BundleNumber ] . " ;";

以及

 $sql = "SELECT `ArchiveBundle`.`QtyIssued`, `ArchiveBundle`.`WorksOrder`,
                `ArchiveBundle`.`Colour`, `ArchiveBundle`.`Size`
         FROM `ArchiveBundle`
         WHERE `ArchiveBundle`.`KordNo` =  " . $x[ KordNo ] . "  
           AND `ArchiveBundle`.`BundleNumber` =  " . $x[ BundleNumber ] . " ;";

这似乎多余。

另外,你在此提及<条码>x,但<条码>x只是一个指数变量,用以生成一个 com式扫描仪清单;我怀疑这是你意思的。

My advice is this: figure out what information you re trying to pull from the DB, work out the correct SQL for this data request 以及 then go from there.

根据您的法典,我think。 请问:

   SELECT `scanners`.*, ArchiveBundle`.`QtyIssued`, `Stock`.`ProductGroup`
    FROM `Stock` INNER JOIN `TWOrder` ON 
                    `Stock`.`ProductCode` = `TWOrder`.`Product`
                 INNER JOIN `ArchiveBundle` ON
                    `TWOrder`.`WorksOrderNumber` = `ArchiveBundle`.`WorksOrder` AND
                    `TWOrder`.`Colour` = `ArchiveBundle`.`Colour` AND
                    `TWOrder`.`Size` = `ArchiveBundle`.`Size`
                 INNER JOIN `scanners` ON
                    `ArchiveBundle`.`KordNo` = `scanners`.`KordNo` AND 
                    `ArchiveBundle`.`BundleNumber` = `scanners`.`BundleNumber`
    WHERE `scanners`.`Scanners` IN (?...?)";




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签