0

我有一个问题,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>

                                <?  } ?>
4

1 回答 1

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>

                            <?  
                        } ?>
于 2013-10-02T07:04:58.763 回答