Jump to content

[SOLVED] php grouping output


seefor

Recommended Posts

Sorry for the silly question, I'm new to PHP  ;D ;D

 

Below is my report.php file:

<?php require_once('../Connections/Sencore.php'); ?>
<?php
mysql_select_db($database_Sencore, $Sencore);
$query_subVer = "SELECT * FROM `1067`";
$subVer = mysql_query($query_subVer, $Sencore) or die(mysql_error());
$row_subVer = mysql_fetch_assoc($subVer);
$totalRows_subVer = mysql_num_rows($subVer);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="../assets/css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<table border="1">
  <tr>
    <td>IPAddress</td>
    <td>Notes</td>
    <td>alias</td>
    <td>unitversion</td>
    <td>decoderVersion</td>
    <td>tssid</td>
    <td>stationname</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_subVer['IPAddress']; ?></td>
      <td><?php echo $row_subVer['Notes']; ?></td>
      <td><?php echo $row_subVer['alias']; ?></td>
      <td><?php echo $row_subVer['unitversion']; ?></td>
      <td><?php echo $row_subVer['decoderVersion']; ?></td>
      <td><?php echo $row_subVer['tssid']; ?></td>
      <td><?php echo $row_subVer['stationname']; ?></td>
    </tr>
    <?php } while ($row_subVer = mysql_fetch_assoc($subVer)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($subVer);
?>

 

The output looks like this:

10.67.10.56 RX BU AUSTIN 6.3.0 6.3.0

10.67.10.35 RX 04 AUSTIN 6.3.0 6.3.0

10.67.10.34 RX 03 AUSTIN 6.3.0 6.3.0

10.67.10.33 RX 02 AUSTIN 6.3.0 6.3.0

10.67.10.32 RX 01 AUSTIN 6.3.0 6.3.0

10.67.12.56 RX BU DALLAS 6.3.0 6.3.0

10.67.12.35 RX 04 DALLAS 6.3.0 6.3.0

10.67.12.34 RX 03 DALLAS 6.3.0 6.3.0

10.67.12.33 RX 02 DALLAS 6.3.0 6.3.0

10.67.12.32 RX 01 DALLAS 6.3.0 6.3.0

 

What I'm trying to accomplish is that the output looks like this:

AUSTIN

10.67.10.56 RX BU 6.3.0 6.3.0

10.67.10.35 RX 04 6.3.0 6.3.0

10.67.10.34 RX 03 6.3.0 6.3.0

10.67.10.33 RX 02 6.3.0 6.3.0

10.67.10.32 RX 01 6.3.0 6.3.0

 

DALLAS

10.67.12.56 RX BU 6.3.0 6.3.0

10.67.12.35 RX 04 6.3.0 6.3.0

10.67.12.34 RX 03 6.3.0 6.3.0

10.67.12.33 RX 02 6.3.0 6.3.0

10.67.12.32 RX 01 6.3.0 6.3.0

 

I have no clue what to google to find something similar to this... ??? ??? ???

 

Any suggestions would greatly help, thanks in advance.

 

SeeFor

Link to comment
https://forums.phpfreaks.com/topic/146555-solved-php-grouping-output/
Share on other sites

try

<?php require_once('../Connections/Sencore.php'); ?>
<?php
mysql_select_db($database_Sencore, $Sencore);
$query_subVer = "SELECT * FROM `1067` ORDER BY decoderVersion";
$subVer = mysql_query($query_subVer, $Sencore) or die(mysql_error());
$row_subVer = mysql_fetch_assoc($subVer);
$totalRows_subVer = mysql_num_rows($subVer);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="../assets/css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<table border="1">
  <tr>
    <td>IPAddress</td>
    <td>Notes</td>
    <td>alias</td>
    <td>unitversion</td>
    
    <td>tssid</td>
    <td>stationname</td>
  </tr>
  <?php 
  $curr_dec='';
  do { 
  if ($row_subVer['decoderVersion'] != $curr_dec){
  	echo "<tr><td colspan=\"6\">decoderVersion: $row_subVer[decoderVersion]</td></tr>";
  	$curr_dec = $row_subVer['decoderVersion'];
  }
  ?>
    <tr>
      <td><?php echo $row_subVer['IPAddress']; ?></td>
      <td><?php echo $row_subVer['Notes']; ?></td>
      <td><?php echo $row_subVer['alias']; ?></td>
      <td><?php echo $row_subVer['unitversion']; ?></td>
      
      <td><?php echo $row_subVer['tssid']; ?></td>
      <td><?php echo $row_subVer['stationname']; ?></td>
    </tr>
    <?php } while ($row_subVer = mysql_fetch_assoc($subVer)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($subVer);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.