duanjiao5082 2016-06-14 20:30
浏览 42
已采纳

混淆数据库中的显示数据

i want to display data from database. i want to display 4 tables named 'score', 'listening_score', 'reading_score' and 'structure_score'. 'score' table contained final 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>";
?>

i want to display:

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

BUT when i test twice, data will be displaying like this:

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

I want to display like this:

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

this is my table structure:

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条回答 默认 最新

  • dsgdg46465 2016-06-14 23:36
    关注

    What u show in PHP code is to make circle in circle no wonder it will go out to be like ABCDDCB nesting. From the tables you built, I can see no relation between the four tables but for the email field. I suggest u to add total_score field in the tables except for score table. And select sentences constrain to the unique one with email and total_score. Code like following:

    picture 1

    picture 2

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部