gpt4 book ai didi

php - 在同一行的第二次出现时在列内打印不同的值

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:16 25 4
gpt4 key购买 nike

我有一张表,我可以在其中打印来自数据库的数据。有时同名的外观可能不止一种。 enter image description here如您所见,名称相同但过程不同。这是我的表格:

  <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实现这一目标?谢谢

最佳答案

# In this array we will store first ids
$dataIds = array();
<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"];
$duplicate = "";

if (!in_array($staffid, $dataIds)) {
array_push($dataIds, $stafid);
} else {
$duplicate = "Duplicate";
}

$longnm=$row["longname"]. "($duplicate)";
$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>

此处将在全名旁边显示重复项。

关于php - 在同一行的第二次出现时在列内打印不同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43885857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com