Ailyn
Ailyn

Reputation: 295

Syntax error when using if and using query inside another query

I'm working with displaying an output when I count the value of the second query is greater than or equal to 2 , using the first query where second query schedule number is equal to the first query schedule number.

The line that I got an error:

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

I just got this message syntax error, unexpected'.'

My whole code is this:

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

What is the following solution about this?

Upvotes: 2

Views: 41

Answers (1)

Lekens
Lekens

Reputation: 1969

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

Upvotes: 3

Related Questions