gpt4 book ai didi

php - 让用户从数据库中选择某人 PHP

转载 作者:行者123 更新时间:2023-11-28 23:38:50 27 4
gpt4 key购买 nike

假设我们根据用户标准执行查询。完成此查询后,我向用户展示了一个数组,其中包含符合他的条件的所有人员。

像这样:

请注意,我在每个人的右侧添加了一个按钮,由于此数组是动态的,因此我正在努力弄清楚如何知道选择了哪个人。

我发布了这个代码(但是,它很长......)

$sql1 = "SELECT DISTINCT pid FROM open_position, person
WHERE open_position.cid=$s_cid AND (person.prof=open_position.field
OR person.studies LIKE '%open_position.studies%'
OR person.skillz LIKE '%open_position.skillz%'
OR person.languages LIKE '%open_position.pref_languages%')";

if ($result1 = mysqli_query($dbconn, $sql1)){

$data = array();
while ($row = mysqli_fetch_assoc($result1)) {
$data[] = $row["pid"];
}

mysqli_free_result($result1);

?>
<table style="float:center" class="table_center">
<tr>
<th id="top_left">pid</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
<th>Studies</th>
<th>Skills</th>
<th>Languages</th>
<th>Hired</th>
<th id="top_right">Available From</th>
</tr>

<?php
$size = count($data);
$i = 0;
while ($i < $size) {
$sql2 = "SELECT * FROM person WHERE pid = '$data[$i]'";
if ($result2 = mysqli_query($dbconn, $sql2)) {
while ($row2 = mysqli_fetch_array($result2)) {
?>
<tr>
<td>
<?php
echo $row2['pid'];
?>
</td>
<td>
<?php
echo $row2['first_name'];
?>
</td>
<td>
<?php
echo $row2['last_name'];
?>
</td>
<td>
<?php
echo $row2['address'];
?>
</td>
<td>
<?php
echo $row2['studies'];
?>
</td>
<td>
<?php
echo $row2['skillz'];
?>
</td>
<td>
<?php
echo $row2['languages'];
?>
</td>
<td>
<?php
if ($row2['hired'] == "1"){
echo "YES";
}
else {
echo "NO";
}
?>
</td>
<td>
<?php
echo $row2['availability'];
?>
</td>
<td>
<input type="submit" class="button" name="hire" value="HIRE
<?php
$_SESSION['hired_pid'] = $data[$i];

?>"></input>
</td>
<tr>
<?php
}
}

$i = $i + 1;
}
?></table>
<?php
}

有什么想法吗???

最佳答案

好的实现这个。对于按钮本身,您可以添加它以重定向到其中包含人员 ID 的 url。类似这样。

<a href='hire.php?pid=<?=$row2['pid'];?>'><input type='button' value='hire' /></a>

在 hire.php 中获取人的 id,然后做任何你想做的事。这可以根据您的要求以多种方式完成。这只是一个示例想法。

关于php - 让用户从数据库中选择某人 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34935264/

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