English 中文(简体)
合并两个田地,使用Sandql
原标题:Merge two fields together using php and mysql
  • 时间:2011-10-18 15:13:49
  •  标签:
  • php
  • mysql

参看以下准则:

  $query = "
          SELECT * FROM Question q
            INNER JOIN StudentAnswer sa ON q.QuestionId = sa.QuestionId
            JOIN Answer a ON sa.QuestionId = a.QuestionId  
          WHERE
            ( ".mysql_real_escape_string($sessionid)."  =    OR q.SessionId =  ".mysql_real_escape_string($sessionid)." )
          AND
            ( ".mysql_real_escape_string($questionno)."  =    OR q.QuestionNo =  ".mysql_real_escape_string($questionno)." )
          AND
            ( ".mysql_real_escape_string($studentid)."  =    OR sa.StudentId =  ".mysql_real_escape_string($studentid)." )
          AND(CorrectAnswer =  1 )
          ORDER BY $orderfield ASC";
while ($row = mysql_fetch_array($result)) {
          echo "
      <tr>
      <td>{$row[ SessionId ]}</td>
      <td>{$row[ QuestionNo ]}</td>
      <td>{$row[ QuestionContent ]}</td>
      <td>{$row[ AnswerContent ]}</td>
      <td>{$row[ StudentAnswer ]}</td>
      <td>{$row[ Weight% ]}</td>
      <td></td>
      <td>{$row[ StudentId ]}</td>
      </tr>";
        }
      ?>

每一行都是我数据库表的一个领域。 我感兴趣的是:

<td>{$row[ AnswerContent ]}</td>
          <td>{$row[ StudentAnswer ]}</td>

我在问询中援引的WHERE条款,只是正确回答的词。 但是,在数据库表中的真相中,回答者领域包含一行,每个回答者都有一字答案。

学生回答是学生们选择的哪怕回答。 我想的是,对于学生Answer row,我不希望它拿出10、5、2等数字,而是想用 words、蓝、纯等词来显示学生的回答。 因此,我想知道的是,我是如何把回答Content和学生Answer合并在一起的,这样,无论学生Answer是怎样的,它都是从学生Answer的田中以言语表示的,而不是以id语表示。

感谢

问题回答

页: 1 只找你想要的领域。 选择所有栏目,不论能否降低维护能力和增加数据库服务器的负荷。

如果你不喜欢,回答,你可以总是在上进行第二次询问。 查阅与<代码>对应的答复文本内容的表格。 然而,这不会像回答你先前的问题那样有效。

Without any precise definitions of your schema, it s a little harder to write an actual query tailored to your problem.





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...