使用if并在另一个查询中使用查询时出现语法错误

时间:2017-08-04 09:32:44

标签: 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;
?>

以下解决方案是什么?

1 个答案:

答案 0 :(得分:2)

<?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;
        ?>