PHP脚本+ MySQL只返回一行

时间:2013-10-01 20:05:45

标签: php mysql

我遇到一个问题,PHP页面只返回一行而不是一对。 它应该在表中很好地返回多行,但它不会... 如果我删除出现的行,它将显示下一行(但仍然是一行)。

更新: 对不起,我没有解释问题是哪个MySQL查询。 它是关于“SELECT * FROM users WHERE active = 2 ...”

PS:我知道我应该使用MySQL而不是PDO或MySQLi,但我很快就会改变它。

     <? $result = mysql_query("SELECT * FROM school WHERE schoolid = '$schoolvanleerling'"); while($row = mysql_fetch_array($result)){
    echo $schoolnaam = $row['schoolnaam'];

     } ?>.

    </p><br>
    <h3>Actieve tutors</h3>
                <table class="demotable" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <th>Naam tutor</th>
                                    <th>Klas tutor</th>
                                    <th>Vakken tutor</th>
                                    <th>Rating tutor</th>
                                    <th>Cijfer tutor</th>
                                    <th>Acties</th>
                                </tr>
<? $result = mysql_query("SELECT * FROM users WHERE active = '2' AND bijles_school = '$schoolvanleerling' ORDER BY name ASC"); while($row = mysql_fetch_array($result)){
 ?>

                                    <tr>
                                        <td><a href="profiel.php?id=<? echo $row['id'];?>"><? echo $row['name'];?></a></td>
                                        <td><? $result = mysql_query("SELECT * FROM klas WHERE id = '$row[klas]'"); while($rowa = mysql_fetch_array($result)){ ?><? echo $rowa['naam'];?><? }?></td>
                                        <td> <? $bijlesvakkenn = explode(",", $row['bijles_tutor']); 
     foreach ($bijlesvakkenn as $value) {
    ?>
    <? $result = mysql_query("SELECT * FROM vakken WHERE id = '$value' ORDER BY naam ASC"); while($rowvak = mysql_fetch_array($result)){ 
     echo $rowvak['naam'];?><br><? } } ?></td>
                                        <td><? // echo getRating($row['id']); ?></td>
                                        <td>nog geen cijfer beschikbaar</td>
                                        <td>- Deactiveer Tutor<br>- <a href="mailto:<? echo $row['email'];?>">Contact opnemen</a></td>
                                    </tr>

                                    <?  } ?>
                                </table>
    <br><br>
    <h3>Niet goedgekeurde tutors</h3>
                    <table class="demotable" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <th>Naam tutor</th>
                                        <th>Klas tutor</th>
                                        <th>Vakken tutor</th>
                                        <th>Rating tutor</th>
                                        <th>Cijfer tutor</th>
                                        <th>Acties</th>
                                    </tr>
    <? $result = mysql_query("SELECT * FROM users WHERE active = '1' AND bijles_school = '$schoolvanleerling' ORDER BY

 name ASC"); while($row = mysql_fetch_array($result)){
 ?>
                                <tr>
                                    <td><? echo $row['name'];?></td>
                                    <td><? $result = mysql_query("SELECT * FROM klas WHERE id = '$row[klas]'"); while($rowa = mysql_fetch_array($result)){ ?><? echo $rowa['naam'];?><? }?></td>
                                    <td> <? $bijlesvakkenn = explode(",", $row['bijles_tutor']); 
 foreach ($bijlesvakkenn as $value) {

?>
<? $result = mysql_query("SELECT * FROM vakken WHERE id = '$value' ORDER BY naam ASC"); while($row = mysql_fetch_array($result)){ 
 echo $row['naam'];?><br><? } } ?></td>
                                    <td><? echo getRating($row['id']); ?></td>
                                    <td>8</td>
                                    <td>- Deactiveer Tutor<br>- Contact opnemen</td>
                                </tr>

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

更新的工作代码: 更改是我不再使用$ result多次

 <? $resultschool = mysql_query("SELECT * FROM school WHERE schoolid = '$schoolvanleerling'"); while($rowschool = mysql_fetch_array($resultschool)){
echo $schoolnaam = $rowschool['schoolnaam'];
 } ?>.
</p><br>
<h3>Actieve tutors</h3>
                <table class="demotable" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <th>Naam tutor</th>
                                    <th>Klas tutor</th>
                                    <th>Vakken tutor</th>
                                    <th>Rating tutor</th>
                                    <th>Cijfer tutor</th>
                                    <th>Acties</th>
                                </tr>
<? $result = mysql_query("SELECT * FROM users WHERE active = 2 AND bijles_school = '$schoolvanleerling' ORDER BY name ASC"); while($row = mysql_fetch_array($result)){
 ?>
                                <tr>
                                    <td><a href="profiel.php?id=<? echo $row['id'];?>"><? echo $row['name'];?></a></td>
                                    <td><? $resulta = mysql_query("SELECT * FROM klas WHERE id = '$row[klas]'"); while($rowa = mysql_fetch_array($resulta)){ ?><? echo $rowa['naam'];?><? }?></td>
                                    <td> <? $bijlesvakkenn = explode(",", $row['bijles_tutor']); 
 foreach ($bijlesvakkenn as $value) {

?>
<? $resultvak = mysql_query("SELECT * FROM vakken WHERE id = '$value' ORDER BY naam ASC"); while($rowvak = mysql_fetch_array($resultvak)){ 
 echo $rowvak['naam'];?><br><? } } ?></td>
                                    <td><? // echo getRating($row['id']); ?></td>
                                    <td>nog geen cijfer beschikbaar</td>
                                    <td>- <a href="mijnprofiel.php?do=manageschool&action=deactivatetutor&id=<? echo $row['id'];?>">Deactiveer Tutor</a><br>- <a href="mailto:<? echo $row['email'];?>">Contact opnemen</a></td>
                                </tr>

                                <?  } ?>

1 个答案:

答案 0 :(得分:0)

您只需从您的代码中替换此代码我认为其工作

   <? $resultschool = mysql_query("SELECT * FROM school WHERE schoolid = '$schoolvanleerling'");

   while($rowschool = mysql_fetch_array($resultschool))
   {
     $schoolnaam = $rowschool['schoolnaam'];
     } ?>
    </p><br>
     <h3>Actieve tutors</h3>
            <table class="demotable" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <th>Naam tutor</th>
                                <th>Klas tutor</th>
                                <th>Vakken tutor</th>
                                <th>Rating tutor</th>
                                <th>Cijfer tutor</th>
                                <th>Acties</th>
                            </tr>
      <? $result = mysql_query("SELECT * FROM users WHERE active = 2 AND bijles_school = '$schoolvanleerling' ORDER BY name ASC");

  while($row = mysql_fetch_array($result)){
        ?>
                            <tr>
                                <td><a href="profiel.php?id=<? echo $row['id'];?>"><?            echo $row['name'];?></a></td>
                                <td><? $resulta = mysql_query("SELECT * FROM klas WHERE id = '$row[klas]'");
                                 while($rowa = mysql_fetch_array($resulta)){
                                  echo $rowa['naam'];
                                   }?></td>
                                <td> <? $bijlesvakkenn = explode(",", $row['bijles_tutor']); 
                                foreach ($bijlesvakkenn as $value) {
                                                                     $resultvak = mysql_query("SELECT * FROM vakken WHERE id = '$value' ORDER BY naam ASC"); 
                                                                     while($rowvak = mysql_fetch_array($resultvak)){ 
                                                                        echo $rowvak['naam']."<br>";
                                                                         } 
                                                                    } ?></td>
                                <td><? // echo getRating($row['id']); ?></td>
                                <td>nog geen cijfer beschikbaar</td>
                                <td><a href="mijnprofiel.php?do=manageschool&action=deactivatetutor&id=<? echo $row['id'];?>">Deactiveer Tutor</a><br>- <a href="mailto:<? echo $row['email'];?>">Contact opnemen</a></td>
                            </tr>

                            <?  
                        } ?>