gpt4 book ai didi

php - 如何使用表中的属性作为变量?

转载 作者:行者123 更新时间:2023-11-30 00:59:35 25 4
gpt4 key购买 nike

我有这个代码:

$emp_id=$_POST['Personal_ID'];    

echo"$emp_id";
$sql="select distinct * from dir, training_list_of_dir, trainings_of_dir
where dir.personal_id=trainings_of_dir.personal_id and trainings_of_dir.training_tag=training_list_of_dir.training_tag
and trainings_of_dir.Personal_ID='$emp_id'";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}

$result= mysqli_query($con,$sql);
echo"<table border='1'>
<tr>
<th>second name</th>
<th>First name</th>
<th>Training tag</th>
<th>Training_name</th>
<th>Date of last training</th>
<th>Date of next training</th>
</tr>";
while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>","<a href='some.php'>". $row['Second_name']."</a>", "</td>";
echo "<td>","<a href='some.php'>".$row['First_name']."</a>" ,"</td>";
echo "<td>","<a href='some.php'>". $row['Training_tag']. "</a>" ,"</td>";
echo "<td>","<a href='some.php'>".$row['Training_name']. "</a>" ,"</td>";
echo "<td>","<a href='some.php'>".$row['Date_of_last_training']. "</a>" ,"</td>";
echo "<td>","<a href='some.php'>". $row['Date_of_next_training']. "</a>" ,"</td>";
echo "</tr>";
}

echo "</table>";

我想将表中的每个链接用于其他用途。例如,如果我单击训练标签,它将显示表中带有训练标签的行。或者,如果我点击Date_of_last_training,它将向我显示该日期接受培训的所有人员。

所以问题是,当它显示包含行的表时,如何在 where 子句中使用属性名称?例如,对于“上次训练的日期”,如何在 where date_of_last_training = $date_of_last_training 中获取此日期(从单击属性的表中)?

最佳答案

使用此代码更改 while 循环。在 some.php 页面代码中,您的逻辑基于类型

 while ($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><a href='some.php'>". $row['Second_name']."</a></td>";
echo "<td><a href='some.php'>".$row['First_name']."</a></td>";
echo "<td><a href='some.php?type=traintag&tag=".$row['Training_tag']."'>". $row['Training_tag']. "</a></td>";
echo "<td><a href='some.php?type=trainname&tname=".$row['Training_name']."'>".$row['Training_name']. "</a></td>";
echo "<td><a href='some.php?type=lasttrain&date=".$row['Date_of_last_training'].">".$row['Date_of_last_training']. "</a></td>";
echo "<td><a href='some.php?type=nexttrain&date=".$row['Date_of_next_training']."'>". $row['Date_of_next_training']. "</a></td>";
echo "</tr>";
}

关于php - 如何使用表中的属性作为变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20265942/

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