• <small id='gcwAf'></small><noframes id='gcwAf'>

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

        SQL 选择字符串不起作用

        SQL Select string not working(SQL 选择字符串不起作用)
        <i id='3oH1y'><tr id='3oH1y'><dt id='3oH1y'><q id='3oH1y'><span id='3oH1y'><b id='3oH1y'><form id='3oH1y'><ins id='3oH1y'></ins><ul id='3oH1y'></ul><sub id='3oH1y'></sub></form><legend id='3oH1y'></legend><bdo id='3oH1y'><pre id='3oH1y'><center id='3oH1y'></center></pre></bdo></b><th id='3oH1y'></th></span></q></dt></tr></i><div id='3oH1y'><tfoot id='3oH1y'></tfoot><dl id='3oH1y'><fieldset id='3oH1y'></fieldset></dl></div>
        • <bdo id='3oH1y'></bdo><ul id='3oH1y'></ul>
                <tbody id='3oH1y'></tbody>
              1. <tfoot id='3oH1y'></tfoot>

                1. <legend id='3oH1y'><style id='3oH1y'><dir id='3oH1y'><q id='3oH1y'></q></dir></style></legend>
                2. <small id='3oH1y'></small><noframes id='3oH1y'>

                  本文介绍了SQL 选择字符串不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经发布了这个,但我想更好地解释它.我有一个网站,学生在其中插入他们的 4 门课程和每门课程的 4 条评论,这些是 SQL 表列:课程 1、课程 2、课程 3、课程 4、评论 1、评论 2、评论 3、评论 4.

                  我有一个搜索,任何学生都可以在其中输入地理(可以保存在四个课程列中的任何一个中),并且我希望我的 SQL 查询返回地理的所有评论.例如,如果学生在 Course2 位置保存了 Geography,我希望我的 SQL 查询选择 comment2,其中 course2 = geography.他可能已经保存在course1中了,所以要灵活一些,但只能选择学生选择的课程.这是我当前的 SQL 查询:

                  $SQL = "SELECT (Comment1 FROM Students WHERE Course1 = 'geography'), (Comment2 FROM Students WHERE Course2 = 'geography'), (Comment3 FROM Students WHERE Course3 = 'geography'), (Comment4 FROM学生 WHERE Course4 = '地理')";

                  目前,此 SQL 查询不起作用.我知道这种结构可能看起来很奇怪,但从逻辑上讲,正如您可能理解的那样,这是有道理的,尽管这可能不是正确的编码方式.然后我像这样打印所有的地理评论:

                  $null = '';if(mysql_num_rows($result)) {echo "

                    ";而 ($row=mysql_fetch_array($result)) {if($row["Class"]!=$null) {if($null!='') {echo "</ol><ol type='1'>";}}echo "<li><p>"."".$row["Comment1"]."".$row["Comment2"]." " .$row["Comment3"] ."".$row["Comment4"] ."</li></p>";$i = $i +1;}echo "</ol>";

                  解决方案

                  假设表结构真的(原文如此)不能改变(不再)我会选择 UNION 这里

                   ( SELECT Comment1 as comment FROM soFoo WHERE Course1='geography' )联合所有( SELECT Comment2 as comment FROM soFoo WHERE Course2='geography' )联合所有( SELECT Comment3 as comment FROM soFoo WHERE Course3='geography' )联合所有( SELECT Comment4 as comment FROM soFoo WHERE Course4='geography' )

                  它至少给 MySQL 一个使用索引查找匹配记录的机会.

                  I've already posted this but I want to explain it better. I have a website in which students insert their 4 courses and 4 comments for each course, these are the SQL table columns: Course1, Course2, Course 3, Course 4, Comment1, Comment2, Comment 3, Comment 4.

                  I have a search in which any student inputs, for instance, geography (which may be saved in any of the four course columns), and I want my SQL query to return all the comments for geography. For example, if a student saved Geography in position Course2, I want my SQL query to select comment2 where course2 = geography. He may have saved it in course1, so it has to be flexible, but only select the course chosen by the student. This is my current SQL query:

                  $SQL = "SELECT (Comment1 FROM Students WHERE Course1 = 'geography'), (Comment2 FROM Students WHERE Course2 = 'geography'), (Comment3 FROM Students WHERE Course3 = 'geography'),  (Comment4 FROM Students WHERE Course4 = 'geography')";
                  

                  Currently, this SQL query isn't working. I know the structure may seem odd, but logically, as you may understand, this makes sense, though it's probably not the right way to code it. I then print all the geography comments like this:

                  $null = '';
                  if(mysql_num_rows($result)) {
                    echo "<ol>";  
                   while ($row=mysql_fetch_array($result)) {
                    if($row["Class"]!=$null) {  
                    if($null!='') {  
                    echo "</ol><ol type='1'>";   
                    } 
                   }
                  
                   echo "<li><p>" . " " . $row["Comment1"]. " " . $row["Comment2"]." " .    $row["Comment3"] . " " . $row["Comment4"] . "</li></p>";
                  $i = $i +1;
                  }
                  
                  echo "</ol>";
                  

                  解决方案

                  Assuming that table structure really(sic) can't be changed (anymore) I'd go with a UNION here

                      ( SELECT Comment1 as comment FROM soFoo WHERE Course1='geography' )
                  UNION ALL
                      ( SELECT Comment2 as comment FROM soFoo WHERE Course2='geography' )
                  UNION ALL
                      ( SELECT Comment3 as comment FROM soFoo WHERE Course3='geography' )
                  UNION ALL
                      ( SELECT Comment4 as comment FROM soFoo WHERE Course4='geography' )
                  

                  It gives MySQL at least a fighting chance to use indices to find the matching records.

                  这篇关于SQL 选择字符串不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <tfoot id='I1dx2'></tfoot>

                    1. <i id='I1dx2'><tr id='I1dx2'><dt id='I1dx2'><q id='I1dx2'><span id='I1dx2'><b id='I1dx2'><form id='I1dx2'><ins id='I1dx2'></ins><ul id='I1dx2'></ul><sub id='I1dx2'></sub></form><legend id='I1dx2'></legend><bdo id='I1dx2'><pre id='I1dx2'><center id='I1dx2'></center></pre></bdo></b><th id='I1dx2'></th></span></q></dt></tr></i><div id='I1dx2'><tfoot id='I1dx2'></tfoot><dl id='I1dx2'><fieldset id='I1dx2'></fieldset></dl></div>

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

                          <legend id='I1dx2'><style id='I1dx2'><dir id='I1dx2'><q id='I1dx2'></q></dir></style></legend>
                            <tbody id='I1dx2'></tbody>
                            <bdo id='I1dx2'></bdo><ul id='I1dx2'></ul>