混淆数据库中的显示数据

时间:2016-06-15 04:30:12

标签: php mysql

我想显示数据库中的数据。我想显示4个名为'得分',' listening_score',' reading_score'和' structure_score'。 '得分'表包含最终得分。

的index.php

<? php
   echo "Your TOEFL Score, <br>";
         echo "<table class=\"score\">";
         $email = $_SESSION['email'];
         $q = mysql_query("SELECT * FROM score where email='$email'");
         $query = mysql_query("SELECT * FROM structure_score where email='$email'");
         $query1 = mysql_query("SELECT * FROM listening_score where email='$email'");
         $query2 = mysql_query("SELECT * FROM reading_score where email='$email'");
         while ($row = mysql_fetch_array($q)) {
            echo "
               <h3> <span >".$row['Score']."</span> </h3>";

         while ($row = mysql_fetch_array($query)) {
            echo "
               <tr><td>Score Structure: </td> <td>".$row['Score']."</td><td>Right Answer: </td> <td>".$row['Right_Answer']."</td></tr>";   

         while ($row = mysql_fetch_array($query1)) {
            echo "
               <tr><td>Score Listening: </td> <td>".$row['Score']."</td><td>Right Answer: </td> <td>".$row['Right_Answer']."</td></tr>";

         while ($row = mysql_fetch_array($query2)) {
            echo "
               <tr><td>Score Reading: </td> <td>".$row['Score']."</td><td>Right Answer: </td> <td>".$row['Right_Answer']."</td></tr>";
               }
             }
           }
         }
        echo "</table><br><br>";
?>

我想要显示:

233
Score Structure:    24  Right Answer:   0
Score Listening:    24  Right Answer:   0
Score Reading:   22 Right Answer:   0

但是,当我测试两次时,数据将显示如下:

233

263
Score Structure:    24  Right Answer:   0
Score Listening:    24  Right Answer:   0
Score Reading:  22  Right Answer:   0

Score Reading:  31  Right Answer:   12
Score Listening:    33  Right Answer:   10
Score Structure:    32  Right Answer:   8

我想这样显示:

233
Score Structure:    24  Right Answer:   0
Score Listening:    24  Right Answer:   0
Score Reading:  22  Right Answer:   0

263
Score Reading:  31  Right Answer:   12
Score Listening:    33  Right Answer:   10
Score Structure:    32  Right Answer:   8

这是我的表结构:

CREATE TABLE IF NOT EXISTS `score` (
  `email` varchar(30) NOT NULL,
  `Score` int(100) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `listening_score` (
  `email` varchar(30) NOT NULL,
  `Right_Answer` int(100) NOT NULL,
  `Score` int(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `reading_score` (
  `email` varchar(30) NOT NULL,
  `Right_Answer` int(100) NOT NULL,
  `Score` int(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `structure_score` (
  `email` varchar(30) NOT NULL,
  `Right_Answer` int(100) NOT NULL,
  `Score` int(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

1 个答案:

答案 0 :(得分:0)

你在PHP代码中展示的是在圆圈中制作圈子,难怪它会像ABCDDCB嵌套一样出现。 从您构建的表中,我看不到四个表之间的关系,而是email字段。我建议您在表中添加total_score字段,但score表除外。并选择句子约束emailtotal_score的唯一句子。 代码如下:

picture 1

picture 2