阵列打印不正确。多个查询在单个HTML表中

时间:2017-08-31 04:19:14

标签: php html mysql

使用PHP / MySQL,我正在尝试在我们的网络中显示当前正在使用VLAN的数据库。我有3个段,每个段有总共40个VLAN。

细分市场是'dist''核心''nds'。 Dist有10个VLAN,核心有4个,nds有40个。

我设置它的方式,显示的是我的HTML表格中每列的4行。显示核心段的所有4个VLAN ID。

我需要帮助让每个HTML列显示所有与该段相关的VLAN

  $dist = "SELECT * FROM `used_vlans` WHERE segments = 'dist'";
  $core = "SELECT * FROM `used_vlans` WHERE segments = 'core'";
  $nds = "SELECT * FROM `used_vlans` WHERE segments = 'nds'";
  $result_d = mysqli_query($con,$dist);
  $result_c = mysqli_query($con,$core);
  $result_n = mysqli_query($con,$nds);

  echo "<table>
<tr>
  <th width='100' height='18'>DIST</th>
  <th width='120' height='18'>CORE</th>
  <th width='120' height='18'>NDS</th>
</tr>";

  while (($row = mysqli_fetch_assoc($result_d)) && ($row2 = mysqli_fetch_assoc($result_c)) && ($row3 = mysqli_fetch_assoc($result_n))) 
{       
  echo "<tr>";
  echo "<td height='20'>" . $row['vlan_id'] . "</td>";
  echo "<td height='20'>" . $row2['vlan_id'] . "</td>";
  echo "<td height='20'>" . $row3['vlan_id'] . "</td>";
  echo "</tr>";
}

mysqli_close($con);

echo "</table>";


mysql> show columns from used_vlans;
+----------+----------+------+-----+---------+-------+
| Field    | Type     | Null | Key | Default | Extra |    
+----------+----------+------+-----+---------+-------+
| vlan_id  | int(4)   | YES  |     | NULL    |       |
| segments | tinytext | YES  |     | NULL    |       |
| descript | tinytext | YES  |     | NULL    |       |
+----------+----------+------+-----+---------+-------+

^^^ snapshot of the sql columns

  +---------+----------+----------------------------------+
  | vlan_id | segments | descript                         |
  +---------+----------+----------------------------------+
  |       1 | dist | default                          |
  |       8 | dist | x.y.0.0/22-Srvr                |
  |      10 | dist | VLAN00w.                        |
  |      11 | dist | VMware_ESX_Hosts_x.y.11.0/24   |
  |      12 | dist | VMware_Prod_x.y.12.0/24        |
  |      13 | dist | VMware_Non-Prod_x.y.13.0/24    |
  |      20 | dist | x.y.5.0/24-Srvr_Prod           |
  |      21 | dist | SeaChange_Prod_x.y.21.0/24     |
  |      22 | dist | SeaChange_Non-Prod_x.y.22.0/24 |
  |      30 | dist | x.y.30.0/24-Srvr_Backup        |
  |      31 | dist | DEV_x.y.31.0/24                |
  |     253 | core | icoms_csl_fw_x.y.253.x/24      |
  |     392 | core | x.3.32.x/24                     |
  |     950 | core | CORE_VDC_vPC_peer_link_Native    |
  |     980 | core | InterCoreVDCRouting              |
  |       2 | nds  | native_Dist5_to_Dist6_4Gb_EthCh  |
  |       4 | nds  | native_Dist5_to_NX6_4Gb_EthCh    |
  |      17 | nds  | RDC_Tools_x.y.17.0/24          |
  |      18 | nds  | Linux/Unix_Admin_x.y.18.0/24   |
  |      19 | nds  | NOC_ESX_Hosts-x.y.19.0/24      |
  |      23 | nds  | DMZ_x.17.1.0/24                |
  |      33 | nds  | CA_t.168.164.0/29              |
  |      70 | nds  | .63.70.0/24  |
  |      71 | nds  | .63.71.0/24    |
  |      72 | nds  | .63.72.0/24   |
  |      73 | nds  | .63.73.0/24 |
  |      74 | nds  | .63.74.0/24  |
  |      75 | nds  | .63.75.0/24    |
  |      76 | nds  | .63.76.0/24   |
  |      77 | nds  | .63.77.0/24 |
  |      94 | nds  | x.0.14.65/27                |
  |      96 | nds  | Telcordia_x.y.14.t.28         |
  |     122 | nds  | Abuse_x.y.14.248/29             |
  |     130 | nds  | Polaris_x.y.14.16/28            |
  |     140 | nds  | Disa_t.168.174.0/29            |
  |     144 | nds  | TSD_Sh_Oracle_RK_t.168.144.x   |
  |     145 | nds  | Unified_Poller_Prod_DB_t.168.1 |
  |     150 | nds  | Trust_x.17.3.0/24              |
  |     292 | nds  | DROP-DMZ-PRIVATE-HOSTS           |
  |     293 | nds  | DROP-SHARED-SERVICES-HOSTS       |
  |     294 | nds  | DROP-DMZ-MGMT-HOSTS              |
  |     295 | nds  | DROP-SHARED-SERVICES-MGMT-HOSTS  |
  |     296 | nds  | DROP-DMZ-PUBLIC-HOSTS            |
  |     301 | nds  | w.3.w..0/22                    |
  |     500 | nds  | x.y.26.0/26                    |
  |     519 | nds  | x.y.28.0/26                    |
  |     520 | nds  | x.y.24.0/24                    |
  |     530 | nds  | x.y.27.0/25                    |
  |     531 | nds  | x.y.27.128/25                  |
  |     540 | nds  | x.y.29.0/24                    |
  |     560 | nds  | Solarwinds2                      |
  |     570 | nds  | Doors_Apps_x.y.31.0/24       |
  |     571 | nds  | ESX_NDC_Vmotion                  |
  |     900 | nds  | Oracle_RAC_HB_t.168.90.x       |
  |     901 | nds  | MS_SQL_DB_Cluster_HB             |
  |     902 | nds  | DMZ_x.16.8.0/24                |
  +---------+----------+----------------------------------+

 ^^^ query results

0 个答案:

没有答案