0

我的 SQL SELECT 语句有问题,我在 Google 和 youtube 上进行了搜索,但什么也没找到。

这是我的PHP代码:

public function loadMark($data){
    dbConn(); 

    $query = "SELECT
        subject.subName
        , mark.mark
    FROM
        itcollage.marktype
        , itcollage.student
    INNER JOIN itcollage.parent 
        ON (student.pId = parent.pId)
    INNER JOIN itcollage.mark 
        ON (mark.stId = student.sId)
    INNER JOIN itcollage.subject 
        ON (mark.subId = subject.subId)
    WHERE 
        parent.pUsername='$data' 
    AND 
        mark.subId = subject.subId LIMIT 2";

    return $result=  mysql_query($query);

}

而且我不想为获得学生证的父母加载正确的分数,但它会不断重复所有科目的分数。

数据如下:

Subject      Mark
--------  | ------
Java 101  |   A
Java 101  |   D
Math 101  |   A
Math 101  |   D
  • Java 101 = A,数学 = D

所以怎么了!!!

这是我调用marks.class.php类的代码

    include '../classes/mark.class.php';

    $mark = new mark();
    $result = $mark->loadMark($user);
    $num = mysql_num_rows($result);

     if ($num == 0) {
?>
         <h2>No Marks for your Kid</h2>
<?php
     } else {
?>
         <h2>Marks</h2>
         <table>
             <thead>
                 <tr>
                     <th>Subject</th>
                     <th>Mark</th> 
                  </tr>
              </thead>
              <tbody>
<?php
                  while ($row = mysql_fetch_object($result)) {
                      $marks = $row->mark;
                      $subject = $row->subName;
?>

                      <tr class="light">
                          <td align="center"><?php echo $subject; ?></td>
                          <td align="center"><?php echo $marks; ?></td>
                      </tr>

 <?php
                   }
 ?>
               </tbody>   
           </table>

谁能告诉我有什么问题?

4

1 回答 1

1

这看起来像问题。您没有为此表指定连接条件。

FROM
    itcollage.marktype
    , itcollage.student

改成:

FROM
    itcollage.marktype 
    INNER JOIN itcollage.student *(add join condition here)*
于 2013-03-24T23:17:21.560 回答