php - 在另一个查询中使用 if 和 using query 时出现语法错误

标签 php syntax syntax-error

当我使用第一个查询计算第二个查询的值大于或等于 2 时,我正在显示输出,其中第二个查询计划编号等于第一个查询计划编号。

我收到错误的行:

if ($x>=2) {.'<button onclick="CreateRevision('.$row['id'].')" type="button" class="btn btn-primary"><span class="fa fa-copy"></span></button>'.} else{}.' .

我刚刚收到这条消息syntax error, unexpected'.'

我的整个代码是这样的:

<?php
    //open connection to mysql db
    include("db_connection.php");
 $data = '                   
                    <table id="tb_jobsched" class="display nowrap table table-bordered" width="100%" cellspacing="0">
                        <thead>
                            <tr>
                                <th width="3%">#</th>
                                <th width="10%">Schedule Number</th>
                                <th width="20%">Item Name</th>
                                <th width="10%">Output</th>                            
                                <th width="10%">Date Created</th>
                                <th width="10%">Expected Date</th>
                                <th width="10%">Prepared By</th>
                                <th width="7%">Status</th>
                                <th width="7%"></th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr>
                                <th width="3%">#</th>
                                <th width="10%">Schedule Number</th>
                                <th width="20%">Item Name</th>
                                <th width="10%">Output</th>                            
                                <th width="10%">Date Created</th>
                                <th width="10%">Expected Date</th>
                                <th width="10%">Prepared By</th>
                                <th width="7%">Status</th>
                                <th width="7%"></th>
                            </tr>
                        </tfoot>';

    $query = "SELECT * FROM prepressjobs WHERE pj_deleted = 0 ORDER BY pj_datecreated DESC";

            if (!$result = mysqli_query($db,$query)) {
                exit(mysqli_error());
            }

            // if query results contains rows then featch those rows 
            if(mysqli_num_rows($result) > 0)
            {
                $number = 1;
                while($row = mysqli_fetch_assoc($result))
                {
                    $data .= '<tr>
                        <td>'.$number.'</td>
                        <td>'.$row['pj_schednum'].'</td>
                        <td>'.$row['pj_itemname'].'</td>
                        <td>'.$row['pj_output'].'</td>
                        <td>'.$row['pj_datecreated'].'</td>
                        <td>'.$row['pj_expectedfinished'].'</td>
                        <td>'.$row['pj_preparedby'].'</td>
                        <td>'.$row['pj_status'].'</td>
                        <td>
                            <div class="btn-group" role="group" aria-label="Button group with nested dropdown">
                                <button  onclick="GetJobDetails('.$row['id'].')"  type="button" class="btn btn-primary"><span class="fa fa-gear"></span></button> 
                                '.
                                $querya = "SELECT COUNT(rm_schednum) AS jobrevision FROM jobrevisions WHERE rm_schednum ='{$row['pj_schednum']}'";
                                $resulta= mysqli_query($db, $querya);
                                $rowa = mysqli_fetch_assoc($resulta);
                                $x=$rowa['jobrevision'];

                                if ($x>=2) {.'<button  onclick="CreateRevision('.$row['id'].')" type="button" class="btn btn-primary"><span class="fa fa-copy"></span></button>'.} else{}.'
                            </div>
                        </td> 
                    </tr>';
                    $number++;
                }
            }
            else
            {
                // records now found 
                $data .= '<tr><td colspan="8">Records not found!</td></tr>';
            }

    $data .= '</table>';

            echo $data;
?>

以下解决方案是什么?

最佳答案

<?php
        <?php
            //open connection to mysql db
            include("db_connection.php");
         $data = '                   
                            <table id="tb_jobsched" class="display nowrap table table-bordered" width="100%" cellspacing="0">
                                <thead>
                                    <tr>
                                        <th width="3%">#</th>
                                        <th width="10%">Schedule Number</th>
                                        <th width="20%">Item Name</th>
                                        <th width="10%">Output</th>                            
                                        <th width="10%">Date Created</th>
                                        <th width="10%">Expected Date</th>
                                        <th width="10%">Prepared By</th>
                                        <th width="7%">Status</th>
                                        <th width="7%"></th>
                                    </tr>
                                </thead>
                                <tfoot>
                                    <tr>
                                        <th width="3%">#</th>
                                        <th width="10%">Schedule Number</th>
                                        <th width="20%">Item Name</th>
                                        <th width="10%">Output</th>                            
                                        <th width="10%">Date Created</th>
                                        <th width="10%">Expected Date</th>
                                        <th width="10%">Prepared By</th>
                                        <th width="7%">Status</th>
                                        <th width="7%"></th>
                                    </tr>
                                </tfoot>';

            $query = "SELECT * FROM prepressjobs WHERE pj_deleted = 0 ORDER BY pj_datecreated DESC";

                    if (!$result = mysqli_query($db,$query)) {
                        exit(mysqli_error());
                    }

                    // if query results contains rows then featch those rows 
                    if(mysqli_num_rows($result) > 0)
                    {
                        $number = 1;
                        while($row = mysqli_fetch_assoc($result))
                        {


                            $data .= "<tr>
                                <td>{$number}</td>
                                <td>{$row['pj_schednum']}</td>
                                <td>{$row['pj_itemname']}</td>
                                <td>{$row['pj_output']}</td>
                                <td>{$row['pj_datecreated']}</td>
                                <td>{$row['pj_expectedfinished']}</td>
                                <td>{$row['pj_preparedby']}</td>
                                <td>{$row['pj_status']}</td>
                                <td>
                                    <div class='btn-group' role='group' aria-label='Button group with nested dropdown'>
                                        <button  onclick='GetJobDetails({$row['id']})'  type='button' class='btn btn-primary'><span class='fa fa-gear'></span></button> 
                                        ";




                                        $querya = "SELECT COUNT(rm_schednum) AS jobrevision FROM jobrevisions WHERE rm_schednum ='{$row['pj_schednum']}'";
                                        $resulta= mysqli_query($db, $querya);
                                        $rowa = mysqli_fetch_assoc($resulta);
                                        $x = $rowa['jobrevision'];



                                        if ($x>=2) {
                              $data .= "<button  onclick='CreateRevision({$row['id']})' type='button' class='btn btn-primary'><span class='fa fa-copy'></span></button>";
    } else{}
                                   $data .=  "</div>
                                </td> 
                            </tr>";
                            $number++;
                        }
                    }
                    else
                    {
                        // records now found 
                        $data .= "<tr><td colspan='8'>Records not found!</td></tr>";
                    }

            $data .= "</table>";

                    echo $data;
        ?>

关于php - 在另一个查询中使用 if 和 using query 时出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45503215/

相关文章:

php - CakePHP 查询后调试之谜

c - respawn :1 mean in c? 是什么意思

Java:内部类中的内部类

sql - 这个查询有什么问题?双引号错误

执行两个条件的 PHP IF 语句

ruby - Rails 错误 - Psych::SyntaxError - YAML

php - 事件页面 - 参加或不参加 - 我将如何实现?

php - Cakephp - 包含(可包含行为)获取太多

ubuntu - Ansible 和剧本。如何将 shell 命令转换为 yaml 语法?

php - 合并 PHP 数组中的重叠范围?