這是antivirus_detail表:PHP:顯示一個列陣列字段
+-----------------------------+--------------+------+-----+---------+-----------
| Field | Type | Null | Key | Default | Extra
|
+-----------------------------+--------------+------+-----+---------+-----------
| Emp_id | int(11) | YES | MUL | NULL |
| Computer_id | int(11) | YES | MUL | NULL |
| Antivirus_id | int(11) | NO | PRI | NULL |auto_incre
ment
| Antivirus_name | varchar(50) | YES | | NULL |
| Antivirus_key | varchar(50) | YES | | NULL |
| Antivirus_installation_date | date | YES | | NULL |
| Antivirus_expiration_date | date | YES | | NULL |
這是hardware_description表:
+------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+----------------+
| Computer_id | int(11) | NO | PRI | NULL | auto_increment |
| Emp_id | int(11) | NO | MUL | NULL | |
| PC_type | varchar(20) | YES | | NULL | |
| Operating_system | varchar(20) | YES | | NULL | |
| Product_key | varchar(30) | YES | | NULL | |
| Assign_date | date | YES | | NULL | |
EMP_ID是從一個不同的員工表& COMPUTER_ID這兩個表的外鍵是來自hardware_description表的防病毒表中的外鍵。
這是我的PHP代碼:
<?php require_once 'includes/dbconnection.php'; ?>
<?php require_once 'includes/functions.php'; ?>
<?php
$id="1";
$sql ="SELECT b.*, c.* FROM hardware_description b, antivirus_detail c WHERE b.Computer_id = c.Computer_id AND c.Emp_id = '$id'";
$result = mysqli_query($connection, $sql);
//var_dump($result);
?>
<table cellpadding="5" border="0">
<tr>
<th style="text-align: left;">Employee ID</th>
<th style="text-align: left;">Computer ID</th>
<th style="text-align: left;">Operating System</th>
<th style="text-align: left;">PC Type</th>
<th style="text-align: left;">Antivirus ID</th>
</tr>
<?php while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $row['Emp_id']; ?></td>
<td><?php echo $row['Computer_id']; ?></td>
<td><?php echo $row['Operating_system']; ?></td>
<td><?php echo $row['PC_type']; ?></td>
<td><?php echo $row['Antivirus_id']; ?></td>
</tr>
<?php
}
?>
</table>
現在,這顯示:
Employee ID Computer ID Operating System PC Type Antivirus ID
1 2 Windows XP Desktop 1
1 2 Windows XP Desktop 2
我所要的輸出是這樣的:
Employee ID Computer ID Operating System PC Type Antivirus ID
1 2 Windows XP Desktop 1,2
我希望所有的殺毒軟件跳到計算機ID的ID將顯示爲數組。我如何實現這一目標?
你想用兩個查詢來做嗎? – 2014-11-24 06:24:27
@IndrasinhBihola我不介意兩個疑問。只需要結果。 – Yugal1458 2014-11-24 06:25:23