pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <bdo id='lwkHW'></bdo><ul id='lwkHW'></ul>
    1. <legend id='lwkHW'><style id='lwkHW'><dir id='lwkHW'><q id='lwkHW'></q></dir></style></legend>
      <tfoot id='lwkHW'></tfoot>
    2. <i id='lwkHW'><tr id='lwkHW'><dt id='lwkHW'><q id='lwkHW'><span id='lwkHW'><b id='lwkHW'><form id='lwkHW'><ins id='lwkHW'></ins><ul id='lwkHW'></ul><sub id='lwkHW'></sub></form><legend id='lwkHW'></legend><bdo id='lwkHW'><pre id='lwkHW'><center id='lwkHW'></center></pre></bdo></b><th id='lwkHW'></th></span></q></dt></tr></i><div class="i8g6yse" id='lwkHW'><tfoot id='lwkHW'></tfoot><dl id='lwkHW'><fieldset id='lwkHW'></fieldset></dl></div>

      <small id='lwkHW'></small><noframes id='lwkHW'>

        過濾結果時是否有更短的方法來設置查詢?

        is there a shorter way to set up queries when filtering results?(過濾結果時是否有更短的方法來設置查詢?)

        <small id='mMcrJ'></small><noframes id='mMcrJ'>

          <tbody id='mMcrJ'></tbody>
            <bdo id='mMcrJ'></bdo><ul id='mMcrJ'></ul>
            • <i id='mMcrJ'><tr id='mMcrJ'><dt id='mMcrJ'><q id='mMcrJ'><span id='mMcrJ'><b id='mMcrJ'><form id='mMcrJ'><ins id='mMcrJ'></ins><ul id='mMcrJ'></ul><sub id='mMcrJ'></sub></form><legend id='mMcrJ'></legend><bdo id='mMcrJ'><pre id='mMcrJ'><center id='mMcrJ'></center></pre></bdo></b><th id='mMcrJ'></th></span></q></dt></tr></i><div class="o22ga24" id='mMcrJ'><tfoot id='mMcrJ'></tfoot><dl id='mMcrJ'><fieldset id='mMcrJ'></fieldset></dl></div>

              <tfoot id='mMcrJ'></tfoot>

                <legend id='mMcrJ'><style id='mMcrJ'><dir id='mMcrJ'><q id='mMcrJ'></q></dir></style></legend>
                1. 本文介紹了過濾結果時是否有更短的方法來設置查詢?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有 2 個下拉菜單,用戶可以在其中使用下拉菜單過濾他們希望看到的學生和問題.可能的過濾器類型有:

                  I have 2 drop down menus where the user can use the drop down menus to filter whih students and questions they wish to see. The possible types of filters are:

                  • 選擇所有學生和所有問題
                  • 選擇所有學生和一個問題
                  • 選擇所有問題和一名學生
                  • 選擇一名學生和一個問題

                  下面是下拉菜單:

                  <p>
                      <strong>Student:</strong>
                      <select name="student" id="studentsDrop">
                      <option value="All">All</option>
                      <?php
                      while ( $currentstudentstmt->fetch() ) {
                      $stu = $dbStudentId;
                      if(isset($_POST["student"]) && $stu == $_POST["student"]) 
                          echo "<option selected='selected' value='$stu'>" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "</option>" . PHP_EOL;
                      else
                          echo "<option value='$stu'>" . $dbStudentAlias . " - " . $dbStudentForename . " " . $dbStudentSurname . "</option>" . PHP_EOL;
                      }
                      ?>
                      </select>
                      </p>
                  
                      <p>
                      <strong>Question:</strong>
                      <select name="question" id="questionsDrop">
                      <option value="All">All</option>
                      <?php
                      while ( $questionsstmt->fetch() ) {
                      $ques = $dbQuestionId;
                      if(isset($_POST["question"]) && $ques == $_POST["question"]) 
                          echo "<option selected='selected' value='$ques'>" . $dbQuestionNo . "</option>" . PHP_EOL;
                      else
                          echo "<option value='$ques'>" . $dbQuestionNo . "</option>" . PHP_EOL;
                      }
                      ?>
                      </select>
                  
                  </p>
                  

                  現在我想設置一個 mysqli 查詢來確定從下拉菜單中選擇的學生和問題.

                  Now I want to set up a mysqli query which determines on the students and questions selected from the drop down menu.

                  我的問題只是我是否需要設置 4 個查詢來檢查我從下拉菜單中提到的 4 種可能性,還是有更短的方法?

                  My question is simply do I need to set up 4 queries checking for the 4 possibilities I mentioned from the drop down menus or is there are a shorter way?

                  我是否必須使用:

                   if ($_POST['question'] == 'All' && if ($_POST['student'] == 'All'){){
                  
                  //NO WHERE CLAUSE
                  
                      if ($_POST['question'] == 'All' && if ($_POST['student'] != 'All'){){
                  
                  //WHERE CLAUSE FOR FINDING SELECTED STUDENT
                  
                      if ($_POST['question'] != 'All' && if ($_POST['student'] == 'All'){){
                  
                  //WHERE CLAUSE FOR FINDING SELECTED QUESTION 
                  
                      if ($_POST['question'] != 'All' && if ($_POST['student'] != 'All'){){
                  
                  //WHERE CLAUSE FOR FINDING SELECTED QUESTION AND SELECTED STUDENT
                  

                  更新:

                  我現在擁有的:

                      function AssessmentIsSubbmitted()
                  {
                      if(isset($_POST['answerSubmit'])) // we have subbmited the first form
                      {
                  
                  //QUERY 1: Student details depending on selected student(s)
                  
                  if ($_POST['student'] == 'All'){
                  
                  $selectedstudentqry = "
                  SELECT
                  StudentAlias, StudentForename, StudentSurname
                  FROM Student s
                  INNER JOIN Student_Session ss ON s.StudentId = ss.StudentId
                  WHERE SessionId = ?
                  ORDER BY StudentAlias
                  ";
                  
                  global $mysqli;
                  $selectedstudentstmt=$mysqli->prepare($selectedstudentqry);
                  // You only need to call bind_param once
                  $selectedstudentstmt->bind_param("i",$_POST["session"]);
                  // get result and assign variables (prefix with db)
                  $selectedstudentstmt->execute(); 
                  $selectedstudentstmt->bind_result($detailsStudentAlias,$detailsStudentForename,$detailsStudentSurname);
                  $selectedstudentstmt->store_result();
                  $selectedstudentnum = $selectedstudentstmt->num_rows();     
                  
                  }else{  
                  
                  $selectedstudentqry = "
                  SELECT
                  StudentAlias, StudentForename, StudentSurname
                  FROM
                  Student
                  WHERE
                  (StudentId = ?)
                  ORDER BY StudentAlias
                  ";
                  
                  global $mysqli;
                  $selectedstudentstmt=$mysqli->prepare($selectedstudentqry);
                  // You only need to call bind_param once
                  $selectedstudentstmt->bind_param("i",$_POST["student"]);
                  // get result and assign variables (prefix with db)
                  $selectedstudentstmt->execute(); 
                  $selectedstudentstmt->bind_result($detailsStudentAlias,$detailsStudentForename,$detailsStudentSurname);
                  $selectedstudentstmt->store_result();
                  $selectedstudentnum = $selectedstudentstmt->num_rows();    
                  
                  }    
                  
                  
                  //QUERY 2: Question details depending on selected question(s)
                  
                  
                  if ($_POST['question'] == 'All'){
                  
                  $selectedquestionqry = " SELECT q.QuestionNo, q.QuestionContent, o.OptionType, q.NoofAnswers, GROUP_CONCAT( DISTINCT Answer
                                      ORDER BY Answer
                                      SEPARATOR ',' ) AS Answer, r.ReplyType, q.QuestionMarks
                                      FROM Question q
                                      LEFT JOIN Answer an ON q.QuestionId = an.QuestionId
                                      LEFT JOIN Reply r ON q.ReplyId = r.ReplyId
                                      LEFT JOIN Option_Table o ON q.OptionId = o.OptionId
                                      WHERE SessionId = ?
                                      GROUP BY q.QuestionId
                                      ORDER BY q.QuestionId";
                  ";
                  
                  global $mysqli;
                  $selectedquestionstmt=$mysqli->prepare($selectedquestionqry);
                  // You only need to call bind_param once
                  $selectedstudentstmt->bind_param("i",$_POST["session"]);
                  // get result and assign variables (prefix with db)
                  $selectedquestionstmt->execute(); 
                  $selectedquestionstmt->bind_result($detailsQuestionNo,$detailsQuestionContent,$detailsOptionType,$detailsNoofAnswers,
                  $detailsAnswer,$detailsReplyType,$detailsQuestionMarks);
                  $selectedquestionstmt->store_result();
                  $selectedquestionnum = $selectedquestionstmt->num_rows(); 
                  
                  
                  }else{
                  
                  $selectedquestionqry = "
                  SELECT q.QuestionNo, q.QuestionContent, o.OptionType, q.NoofAnswers, GROUP_CONCAT( DISTINCT Answer
                                      ORDER BY Answer
                                      SEPARATOR ',' ) AS Answer, r.ReplyType, q.QuestionMarks
                                      FROM Question q
                                      LEFT JOIN Answer an ON q.QuestionId = an.QuestionId
                                      LEFT JOIN Reply r ON q.ReplyId = r.ReplyId
                                      LEFT JOIN Option_Table o ON q.OptionId = o.OptionId
                                      WHERE QuestionId = ?
                                      GROUP BY q.QuestionId
                                      ORDER BY q.QuestionId
                  ";
                  
                  global $mysqli;
                  $selectedquestionstmt=$mysqli->prepare($selectedquestionqry);
                  // You only need to call bind_param once
                  $selectedquestionstmt->bind_param("i",$_POST["question"]);
                  // get result and assign variables (prefix with db)
                  $selectedquestionstmt->execute(); 
                  $selectedquestionstmt->bind_result($detailsQuestionNo,$detailsQuestionContent,$detailsOptionType,$detailsNoofAnswers,
                  $detailsAnswer,$detailsReplyType,$detailsQuestionMarks);
                  $selectedquestionstmt->store_result();
                  $selectedquestionnum = $selectedquestionstmt->num_rows(); 
                  
                  }
                  
                  //QUERY 3: Student Answers depending on selected student(s) and selected question(s)
                  
                  $studentanswerqry = "
                  SELECT
                  sa.StudentId, sa.QuestionId, GROUP_CONCAT(DISTINCT StudentAnswer ORDER BY StudentAnswer SEPARATOR ',') AS StudentAnswer, ResponseTime, MouseClick, StudentMark
                  FROM Student_Answer sa
                  INNER JOIN Student_Response sr ON sa.StudentId = sr.StudentId
                  WHERE
                  (sa.StudentId = ? AND sa.QuestionId = ?)
                  GROUP BY sa.StudentId, sa.QuestionId
                  ";
                  
                  global $mysqli;
                  $studentanswerstmt=$mysqli->prepare($studentanswerqry);
                  // You only need to call bind_param once
                  $studentanswerstmt->bind_param("ii",$_POST["student"], $_POST["question"]);
                  // get result and assign variables (prefix with db)
                  $studentanswerstmt->execute(); 
                  $studentanswerstmt->bind_result($detailsStudentAnswer,$detailsResponseTime,$detailsMouseClick,$detailsStudentMark);
                  $studentanswerstmt->store_result();
                  $studentanswernum = $studentanswerstmt->num_rows(); 
                  
                  
                  }
                  
                  ?>
                  

                  推薦答案

                  您可以迭代地構建一個 WHERE 子句.考慮到 WHERE 子句執行顯式過濾,因此對于您選擇所有"某些內容的情況,您不需要添加任何過濾器.其他過濾器相互建立,所以我們可以簡單地在 WHERE 中使用 AND 將它們連接起來:

                  You can iteratively build a WHERE clause. Consider that a WHERE clause does explicit filtering, so for cases where you're selecting "all" of something, you don't need to add any filters. The other filters build upon each other, so we can simply join them with ANDs in the WHERE:

                  $query = 'SELECT ... FROM ...';
                  
                  // Initially empty
                  $where = array();
                  $parameters = array();
                  
                  // Check whether a specific student was selected
                  if($stu !== 'All') {
                      $where[] = 'stu = ?';
                      $parameters[] = $stu;
                  }
                  
                  // Check whether a specific question was selected
                  // NB: This is not an else if!
                  if($ques !== 'All') {
                      $where[] = 'ques = ?';
                      $parameters[] = $ques;
                  }
                  
                  // If we added to $where in any of the conditionals, we need a WHERE clause in
                  // our query
                  if(!empty($where)) {
                      $query .= ' WHERE ' . implode(' AND ', $where);
                  }
                  
                  $result = prepare_and_execute_query($query, $parameters);
                  

                  <小時>

                  好的,看看您的更新,您有一組相當復雜的查詢,但可以將其合并為一個語句.試試這個:


                  Okay, so looking at your update, you have a fairly complex set of queries, but it's possible to combine it into one statement. Give this a try:

                  SELECT
                      s.StudentId, s.StudentAlias, s.StudentForename,         -- Student fields
                      s.StudentSurname,
                      q.QuestionId, q.QuestionNo, q.QuestionContent,          -- Question fields
                      q.OptionType, q.NoofAnswers, q.Answer, q.ReplyType,
                      q.QuestionMarks,
                      GROUP_CONCAT(DISTINCT sa.StudentAnswer ORDER BY         -- Answer fields
                          sa.StudentAnswer SEPARATOR ',') AS StudentAnswer,
                      sr.ResponseTime, sr.MouseClick, sr.StudentMark
                  FROM Student s
                  INNER JOIN Student_Answer sa ON (s.StudentId = sa.StudentId)
                  INNER JOIN Question q ON (sa.QuestionId = q.QuestionId)
                  INNER JOIN Student_Response sr ON (sa.StudentId = sr.StudentId)
                  WHERE                     -- This WHERE clause may be entirely removed, 
                                            -- depending on the filters
                      s.StudentId = ? AND   -- This is removed if $_POST['student'] is 'All'
                      q.QuestionId = ?      -- This is removed if $_POST['question'] is 'All'
                  GROUP BY sa.StudentId, q.QuestionId
                  

                  我認為這會滿足您的需求.我不太確定哪些字段是 Student_Response 的一部分,哪些是 Student_Answer 的一部分,所以你可能不得不擺弄 SELECT.

                  I think this will do what you want. I wasn't quite sure about which fields are part of Student_Response and which are part of Student_Answer so you might have to fiddle with the columns in the SELECT.

                  不幸的是,這種方法不適用于您的用例.但是我們仍然可以考慮我提出的原始邏輯如何處理您給出的查詢之一:

                  Unfortunately that approach doesn't work for your use case. But we can still consider how the original logic I proposed would work with one of your queries given:

                  $selectedstudentqry = "
                  SELECT
                  StudentAlias, StudentForename, StudentSurname
                  FROM
                  Student ";
                  if($_POST['student'] !== 'All') { // Check here
                      $selectedstudentqry .= "
                      WHERE
                      (StudentId = ?) ";
                  }
                  $selectedstudentqry .= "
                  ORDER BY StudentAlias
                  ";
                  
                  global $mysqli;
                  $selectedstudentstmt=$mysqli->prepare($selectedstudentqry);
                  if($_POST['student'] !== 'All') {
                      // You only need to call bind_param once
                      $selectedstudentstmt->bind_param("i",$_POST["student"]);
                  }
                  // get result and assign variables (prefix with db)
                  $selectedstudentstmt->execute(); 
                  $selectedstudentstmt->bind_result($detailsStudentAlias,$detailsStudentForename,$detailsStudentSurname);
                  $selectedstudentstmt->store_result();
                  $selectedstudentnum = $selectedstudentstmt->num_rows();
                  

                  請注意我們如何簡單地將外部 if 移動到代碼中更具體的位置以減少代碼重復.如果您看到類似的重復,則很有可能您正在做諸如使條件過于寬泛之類的事情.不過,您在嘗試簡化這一過程并減少冗余方面肯定走在正確的軌道上.

                  Notice how we've simply moved the outer ifs to more specific places within the code to decrease code duplication. If you see duplication like you have, there's a very good chance that you're doing something like making your conditionals too broad. You're definitely on the right track with trying to simplify this and reduce redundancy, though.

                  這篇關于過濾結果時是否有更短的方法來設置查詢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                  • <i id='WdRw3'><tr id='WdRw3'><dt id='WdRw3'><q id='WdRw3'><span id='WdRw3'><b id='WdRw3'><form id='WdRw3'><ins id='WdRw3'></ins><ul id='WdRw3'></ul><sub id='WdRw3'></sub></form><legend id='WdRw3'></legend><bdo id='WdRw3'><pre id='WdRw3'><center id='WdRw3'></center></pre></bdo></b><th id='WdRw3'></th></span></q></dt></tr></i><div class="okc8e6e" id='WdRw3'><tfoot id='WdRw3'></tfoot><dl id='WdRw3'><fieldset id='WdRw3'></fieldset></dl></div>
                    <tfoot id='WdRw3'></tfoot>
                    • <legend id='WdRw3'><style id='WdRw3'><dir id='WdRw3'><q id='WdRw3'></q></dir></style></legend>

                      <small id='WdRw3'></small><noframes id='WdRw3'>

                            <bdo id='WdRw3'></bdo><ul id='WdRw3'></ul>
                              <tbody id='WdRw3'></tbody>
                            主站蜘蛛池模板: 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 高压油管,液压接头,液压附件-烟台市正诚液压附件 | 喷砂机厂家_自动除锈抛丸机价格-成都泰盛吉自动化喷砂设备 | 富森高压水枪-柴油驱动-养殖场高压清洗机-山东龙腾环保科技有限公司 | 运动木地板_体育木地板_篮球馆木地板_舞台木地板-实木运动地板厂家 | 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 | 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 全温恒温摇床-水浴气浴恒温摇床-光照恒温培养摇床-常州金坛精达仪器制造有限公司 | 造价工程师网,考试时间查询,报名入口信息-网站首页 | 蔬菜配送公司|蔬菜配送中心|食材配送|饭堂配送|食堂配送-首宏公司 | 检验科改造施工_DSA手术室净化_导管室装修_成都特殊科室建设厂家_医疗净化工程公司_四川华锐 | 中视电广_短视频拍摄_短视频推广_短视频代运营_宣传片拍摄_影视广告制作_中视电广 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 悬浮拼装地板_幼儿园_篮球场_悬浮拼接地板-山东悬浮拼装地板厂家 | 手机存放柜,超市储物柜,电子储物柜,自动寄存柜,行李寄存柜,自动存包柜,条码存包柜-上海天琪实业有限公司 | 盘式曝气器-微孔曝气器-管式曝气器-曝气盘-斜管填料 | 郑州市前程水处理有限公司 | 3d可视化建模_三维展示_产品3d互动数字营销_三维动画制作_3D虚拟商城 【商迪3D】三维展示服务商 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 周易算网-八字测算网 - 周易算网-宝宝起名取名测名字周易八字测算网 | 光纤测温-荧光光纤测温系统-福州华光天锐光电科技有限公司 | 亿立分板机_曲线_锯片式_走刀_在线式全自动_铣刀_在线V槽分板机-杭州亿协智能装备有限公司 | 奥因-光触媒除甲醛公司-除甲醛加盟公司十大品牌 | 食品机械专用传感器-落料放大器-低价接近开关-菲德自控技术(天津)有限公司 | 挤出机_橡胶挤出机_塑料挤出机_胶片冷却机-河北伟源橡塑设备有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 专注提供国外机电设备及配件-工业控制领域一站式服务商-深圳市华联欧国际贸易有限公司 | 北京网站建设首页,做网站选【优站网】,专注北京网站建设,北京网站推广,天津网站建设,天津网站推广,小程序,手机APP的开发。 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 | 分子精馏/精馏设备生产厂家-分子蒸馏工艺实验-新诺舜尧(天津)化工设备有限公司 | 塑木弯曲试验机_铜带拉伸强度试验机_拉压力测试台-倾技百科 | 24位ADC|8位MCU-芯易德科技有限公司 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | 旋片真空泵_真空泵_水环真空泵_真空机组-深圳恒才机电设备有限公司 | 物流公司电话|附近物流公司电话上门取货 | 采暖炉_取暖炉_生物质颗粒锅炉_颗粒壁炉_厂家加盟批发_烟台蓝澳采暖设备有限公司 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 河南卓美创业科技有限公司-河南卓美防雷公司-防雷接地-防雷工程-重庆避雷针-避雷器-防雷检测-避雷带-避雷针-避雷塔、机房防雷、古建筑防雷等-山西防雷公司 | 棉服定制/厂家/公司_棉袄订做/价格/费用-北京圣达信棉服 | 深圳律师咨询_深圳律师事务所_华荣【免费在线法律咨询】网 | 阿里巴巴诚信通温州、台州、宁波、嘉兴授权渠道商-浙江联欣科技提供阿里会员办理 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 |