Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySql查询的组输出_Php_Mysql - Fatal编程技术网

Php MySql查询的组输出

Php MySql查询的组输出,php,mysql,Php,Mysql,我有以下PHP/MySql: $sql = "SELECT * from tblDigest"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<table><tr> <th>Diagram</th> <th>Headcode</th> <th>Date</th>

我有以下PHP/MySql:

$sql = "SELECT * from tblDigest";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

  echo "<table><tr>
    <th>Diagram</th>
    <th>Headcode</th>
    <th>Date</th>
    <th>Dep Time</th>
    <th>Origin</th>
    <th>Destination</th>
    <th>Arr Time</th>
    <th>Booked Traction</th>
    <th>Actual Traction</th>
    <th>Type</th>
    </tr>";

  // output data of each row
  while($row = $result->fetch_assoc()) {

    echo "<tr>";
    echo "<td>" . $row["diagram"] . "</td>";
    echo "<td>" . $row["headcode"] . "</td>";
    echo "<td>" . $row["depDate"] . "</td>";
    echo "<td>" . $row["depTime"] . "</td>";
    echo "<td>" . $row["origin"] . "</td>";
    echo "<td>" . $row["destination"] . "</td>";
    echo "<td>" . $row["arrTime"] . "</td>";
    echo "<td>" . $row["bookedTraction"] . "</td>";
    echo "<td>" . $row["actualTraction"] . "</td>";
    echo "<td>" . $row["type"] . "</td>";

    echo "</tr>";

  }

  echo "</table>";
}
$sql=“选择*fromtbdigest”;
$result=$conn->query($sql);
如果($result->num_rows>0){
回声“
图解
头号
日期
Dep时间
起源
目的地
到达时间
预定牵引
实际牵引力
类型
";
//每行的输出数据
而($row=$result->fetch_assoc()){
回声“;
回显“$row[“diagram”]”;
回显“$row[“headcode”]”;
回显“$row[“depDate”]”;
回显“$row[“depTime”]”;
回显“$row[“origin”]”;
回显“$row[“destination”]”;
回显“$row[“arrTime”]”;
回显“$row[“bookedTraction”]”;
回显“$row[“actualTraction”]”;
回显“$行[”类型“]”;
回声“;
}
回声“;
}
我想通过“图表”对结果进行分组,这样我就可以将它们显示为手风琴。有什么简单的方法可以做到这一点吗


否则,如何获取表的第一行的值(这样我就可以使用
$diagNo
变量并将
$row[“diagram”]
与该变量进行比较,以确定它何时发生了更改。

根据
diagram
对结果进行排序,并观察其值何时发生更改:

$sql = "SELECT * from tblDigest ORDER BY diagram";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

  echo "<table><tr>
    <th>Diagram</th>
    <th>Headcode</th>
    <th>Date</th>
    <th>Dep Time</th>
    <th>Origin</th>
    <th>Destination</th>
    <th>Arr Time</th>
    <th>Booked Traction</th>
    <th>Actual Traction</th>
    <th>Type</th>
    </tr>";

  // output data of each row
  $oldDiagram = '';
  while($row = $result->fetch_assoc()) {

    if($oldDiagram == '')
    {
      // this is the first diagram - create the first accordeon
      $oldDiagram = $row['diagram'];
    }
    elseif($oldDiagram != $row['diagram'])
    {
      // a new group starts right now - create new accordeon
      $oldDiagram = $row['diagram'];
    }
    echo "<tr>";
    echo "<td>" . $row["diagram"] . "</td>";
    echo "<td>" . $row["headcode"] . "</td>";
    echo "<td>" . $row["depDate"] . "</td>";
    echo "<td>" . $row["depTime"] . "</td>";
    echo "<td>" . $row["origin"] . "</td>";
    echo "<td>" . $row["destination"] . "</td>";
    echo "<td>" . $row["arrTime"] . "</td>";
    echo "<td>" . $row["bookedTraction"] . "</td>";
    echo "<td>" . $row["actualTraction"] . "</td>";
    echo "<td>" . $row["type"] . "</td>";

    echo "</tr>";

  }

  echo "</table>";
}
$sql=“从TBLDIGST ORDER BY图表中选择*”;
$result=$conn->query($sql);
如果($result->num_rows>0){
回声“
图解
头号
日期
Dep时间
起源
目的地
到达时间
预定牵引
实际牵引力
类型
";
//每行的输出数据
$oldDiagram='';
而($row=$result->fetch_assoc()){
如果($oldDiagram=='')
{
//这是第一个图表-创建第一个手风琴
$oldDiagram=$row['diagram'];
}
elseif($oldDiagram!=$row['diagram']))
{
//一个新组立即开始-创建新组
$oldDiagram=$row['diagram'];
}
回声“;
回显“$row[“diagram”]”;
回显“$row[“headcode”]”;
回显“$row[“depDate”]”;
回显“$row[“depTime”]”;
回显“$row[“origin”]”;
回显“$row[“destination”]”;
回显“$row[“arrTime”]”;
回显“$row[“bookedTraction”]”;
回显“$row[“actualTraction”]”;
回显“$行[”类型“]”;
回声“;
}
回声“;
}

我不太清楚你想达到什么目的。你能提供一个例子吗?
按图表排序
然后将上一次迭代的
图表
与当前迭代进行比较。按图表排序并在该列的值发生变化时使用变量在循环中进行监控。@ChrisCordner你好,克里斯。如果这个答案是否定的请接受你的问题。