我有一张表从数据库中打印数据。有时可能会出现多个相同名称的外观。 正如您所看到的,具有不同过程的相同名称。这是我的表:
<table>
<?php
$result = getPhData();
echo '
<thead>
<tr>
<th>Staff ID</th>
<th>Full Name</th>
<th>Nicknames</th>
<th>Employment type</th>
<th>Dept:Prod/Other</th>
<th>Number of projects</th>
<th>Many projects?</th>
<th>Ratio per project</th>
<th>Project</th>
<th>Process</th>
<th>Leader</th>
</tr>
</thead>
<?php ';
?>
<tbody>
<?php
$count = 0;
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$staffid=$row["staff_id"];
$longnm=$row["longname"];
$usrnm=$row["username"];
$user_type=$row["user_type"];
$number=$row["number"];
$title=$row["title"];
$code=$row["code"];
$process=$row["process"];
$role=$row["role"];
$ratio=1/$number;
?>
<tr valign="top">
<td><?php echo $staffid; ?></td>
<td><?php echo $longnm; ?></td>
<td><?php echo $usrnm; ?></td>
<td><?php echo $user_type; ?></td>
<td>
<?php if($code=='OPD'){ echo "Others";}
else{echo "Prod";}
?>
</td>
<td><?php echo $number; ?></td>
<td>
<?php if($number==1){ echo "First Occurrence";}
else{echo "Duplicate";}
?>
</td>
<td><?php echo $ratio; ?></td>
<td><?php echo $title; ?></td>
<td>
<?php if($process == NULL)
{ echo $role; }
else{ echo $process; }
?>
</td>
<td>
<?php if($role == 'ld')
{ echo "Yes"; }
else{ echo "";}?>
</td>
</tr>
<?php
$count++;}
}
?>
</tbody>
</table>
我想要的是当相同的id出现在表格中的第二/第三等时间时打印“重复”。我怎样才能通过php实现这一目标?感谢
答案 0 :(得分:1)
int TabCount;
public Development_Adapter(FragmentManager fm,int TabCount) {
super(fm);
this.TabCount=TabCount;
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
Web_development_fragment web_development_fragment=new Web_development_fragment();
return web_development_fragment;
case 1:
Mobileapplication_fragment mobileapplication_fragment=new Mobileapplication_fragment();
return mobileapplication_fragment;
case 2:
Software_development software_development=new Software_development();
return software_development;
default:
return null;
}
}
@Override
public int getCount() {
return TabCount;
}
此处副本将显示在全名旁边。
答案 1 :(得分:1)
您可能需要在添加后使用的每个ID时添加第二个数组,以检查此ID是否已在表中
<?php
$count = 0;
if (mysqli_num_rows($result) > 0)
{
$parsedId = array();
while($row = mysqli_fetch_array($result))
{
if(in_array($row['id'], $parsedId))
//DUPLICATE
else
array_push($parsedId, $row['id']);
/*CODE */
}
}
?>
答案 2 :(得分:1)
你可以用数组来做。收集某个阵列上的员工/人员的ID,然后检查是否有ID in_array。
<?php
$staffs = array();
while($row = mysqli_fetch_array($result)){
$staffid = $row["staff_id"];
$staffs[] = $staffid;
//// your table code.
<td>
<?php if(in_array($row["staff_id"], $staffs)){
echo "First Occurrence";
} else{
echo "Duplicate";
}
?>
</td>
}
?>
另一种方法是,您可以使用SQL
查询来执行此操作。 IF THEN声明。