我可以在SQL中使用AND运算符2次吗?

时间:2019-01-26 09:40:23

标签: php mysql

所以我已经尝试了一个星期,这是我选择日期的提交按钮之后表中的值丢失的原因

因此,进入此页面时,它将显示

'SELECT * FROM attendance WHERE lect_id = 'CS0198289' AND dateofupdate LIKE '%0%' AND codeofsubject = 'CSNB214' ORDER BY studname ASC'

将显示我的lect_id,dateofupdate = 0和主题代码。当我选择迄今为止的Submit(SELECT)按钮时,它将变为

'SELECT * FROM attendance WHERE lect_id = 'CS0198289' AND dateofupdate LIKE '%2019-01-23%' AND codeofsubject = '' ORDER BY studname ASC'

那么有人可以帮助我吗?非常感谢

<?php
                $connect = mysqli_connect ("localhost","root","","ubas")
                or die("Cannot connect to server".mysqli_error($connect));

                if (!isset($_POST['dates'])){
                  $_POST['dates']=0;
                }
                $id = @$_POST["lect_id"];
                $codeofsubject = @$_POST['code'];

                $display = "SELECT * FROM attendance WHERE lect_id = '$_SESSION[id]' AND dateofupdate LIKE '%".$_POST['dates']."%'
                AND codeofsubject = '$codeofsubject' ORDER BY studname ASC";
                echo $display;
                $result = mysqli_query ($connect,$display)
                or die ("Cannot view due to".mysqi_error($connect));

                echo"<form role='form' method='post'>
                        <div class='form-group'>
                          <label>Date</label>
                          <input style='width:180px; display:inline' class='form-control' type='date' name='dates' id='dates'>
                          <button type='submit' style='display:inline' name='select'>Select</button>
                      </div>
                    </form>";

                echo"
                <form method = post action = updateattend.php>
                <table width='100%' class='table table-striped table-bordered table-hover' id='dataTables-example'>
                      <thead>
                          <tr>
                              <th><center>Date</center></th>
                              <th><center>Student Name</center></th>
                              <th><center>Student ID</center></th>
                              <th><center>View</center></th>
                              <th><center>Attend Status</center></th>
                          </tr>
                      </thead>";
                      while($row = mysqli_fetch_array($result,MYSQLI_NUM))
                      {
                        $attendid = $row [0];
                        $studname = $row [1];
                        $studid = $row [2];
                        $lect_id = $row [3];
                        $codeofsubject = $row [4];
                        $date = $row [5];
                        $dateofenroll = $row [6];
                        $attendstatus = $row [7];

                          echo"<tbody>
                          <tr>
                          <td><center>$date</center></td>
                          <td><center>$studname</center></td>
                          <td><center>$studid</center></td>
                          <td align = center>
                          <a class ='btn-warning btn' href ='updatestud.php?id=".$row['2']."'>VIEW</a>
                          </td>";
                          echo"

                          <td align = center>
                          <select class = 'form-control' name = 'attendstatus[]'>
                          <option value='$attendstatus' selected>$attendstatus</option>";

                          if($attendstatus =="Attend")
                          {
                            echo "<option value='Not Attending'>Not Attending</option>
                            <option value='Not Attending with Reason'>Not Attending with Reason</option>";
                          }
                          elseif ($attendstatus =="Not Attending") {
                            echo"<option value='Attend'>Attend</option>
                            <option value='Not Attending with Reason'>Not Attending with Reason</option>";
                          }
                          else{
                            echo"<option value='Attend'>Attend</option>
                            <option value='Not Attending'>Not Attending</option>";
                          }

                          echo"</select>
                          </td>
                        </tr>
                        </tbody>";
                      }

                      ?>
                </table>

1 个答案:

答案 0 :(得分:0)

AND语句中没有SQL个运算符的限制。您可以根据需要使用任意数量的AND,但是从SQL的意义上说,您的逻辑应该是正确的。

例如

SELECT something FROM something WHERE something=something AND something=something AND something=something AND something=something;

因此,something=something部分成为一个独立的逻辑语句,该逻辑语句基于something=something运算符与其他AND语句分开进行评估。但是请记住,上面的整个陈述是一个陈述。