0

このコードを使用するとどうなりますか:

$emailc = 'thomas990428@me.com_classes';
$emaila = 'thomas990428@me.com_assignments';
$emailp = 'thomas990428@me.com_projects';

$resulty = mysqli_query($con,"SELECT * FROM `$emailc` ORDER BY period"); if (!$result) echo mysqli_error(); else // ok, do your thing.
$resulti = mysqli_query($con,"SELECT * FROM `$emaila` ORDER BY duehw"); if (!$result) echo mysqli_error(); else // ok, do your thing.
$resulto = mysqli_query($con,"SELECT * FROM `$emailp` ORDER BY dueproj"); if (!$result) echo mysqli_error(); else // ok, do your thing.

$classcount = 1;


while($row = mysqli_fetch_array($resulty))
  {

  $period = $row['period'];
  $teacher = $row['teacher'];
  $subject = $row['subject'];
  $subjecto = strtolower($subject);
  $subjecto = str_replace(' ', '', $subjecto);
  $grade = $rowy['grade'];

  echo "<section id='" . $subjecto . "'> \n";
  echo "<p class='title'>" . $subject . "</p> \n";
  echo "<a style='cursor:pointer;' onclick='homework" . $classcount . "()'>Homework&nbsp;</a>|<a style='cursor:pointer;' onclick='projects" . $classcount . "()'>&nbsp;Projects</a> \n";
  echo "<div id='homework" . $classcount . "'><br /><a onclick='addassignment()'>Add Assignment</a><br />";
  echo "<table class='homework'>";
  echo "<tr>";
  echo "<th class='title'>";
  echo "Title";
  echo "</th>";
  echo "<th class='duedate'>";
  echo "Due Date";
  echo "</th>";
  echo "</tr>";

  while($row = mysqli_fetch_array($resulti))
    {

      $subjecthw = $row['subjecthw'];
      $namehw = $row['namehw'];
      $duehw = $row['duehw'];

      echo "<tr>";
      echo "<td class='title'>";
      echo $namehw;
      echo "</td>";
      echo "<td class='duedate'>March ";
      echo $duehw;
      echo "</td>";
      echo "</tr>";

    }

  echo "</table>";
  echo "</div> \n";
  echo "<div id='projects" . $classcount . "'><br /><a onclick='addassignment()'>Add Assignment</a><br />";
  echo "<table class='homework'>";
  echo "<tr>";
  echo "<th class='title'>";
  echo "Title";
  echo "</th>";
  echo "<th class='duedate'>";
  echo "Due Date";
  echo "</th>";
  echo "</tr>";

  while($row = mysqli_fetch_array($resulto))
    {

      $subjectproj = $row['subjectproj'];
      $nameproj = $row['nameproj'];
      $dueproj = $row['dueproj'];

      echo "<tr>";
      echo "<td class='title'>";
      echo $nameproj;
      echo "</td>";
      echo "<td class='duedate'>March ";
      echo $dueproj;
      echo "</td>";
      echo "</tr>";

    }

  echo "</table>";
  echo "</div> \n";
  echo "</section> \n";

  $classcount += 1;

  }

hw と proj は 1 つのセクションでしか取得できません。私はそれを間違っていますか?ありがとう!おそらくうまくいかないことはわかっていますが、どうすれば修正できますか?3 つのテーブルがあり、それらすべてからデータを取得する必要があります。

4

1 に答える 1

0

ループ$row内では使用しないでください。while

例えば

while($row = mysql_fetch_row($resulti)){
    while($row2 = mysql_fetch_row($resulto)){

    }
}

また、コードを確認する時間もありませんでしたが、SQL をループで実行することは決して良い考えではありません。

于 2013-05-13T09:55:18.350 に答える