【问题标题】:PHP select only one entry showsPHP 只选择一项显示
【发布时间】:2013-02-24 17:22:13
【问题描述】:

我怎么会用这段代码:

$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;

  }

我只在一个部分中获得了硬件和项目。我做错了吗?谢谢!我知道它可能永远不会起作用,但是我该如何解决呢?我有 3 个表,我需要从所有表中获取数据。

【问题讨论】:

  • 你为什么要让你的服务器如此努力地让 PHP 回显静态元素?
  • 它们是动态的,来自数据库
  • 看来代码绝对没问题,但想知道DB中的肠炎是怎么产生的……
  • 显示的部分,但硬件的东西只显示在一个部分...我有多个部分
  • $grade = $rowy['grade']; 应该是$grade = $row['grade'];

标签: php mysql sql select mysqli


【解决方案1】:

不要在while 循环中使用$row

例如

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

    }
}

也没有时间浏览代码,但循环运行 SQL 绝不是一个好主意。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 1970-01-01
    • 2015-10-08
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多