gpt4 book ai didi

php - 我在搜索过程中只得到一个结果,

转载 作者:行者123 更新时间:2023-11-29 21:15:10 25 4
gpt4 key购买 nike

我有许多具有相同专业知识的记录,每当我搜索时,它只给出一个结果,而 $exp 的值是 array 。假设 $exp=array();我已经尝试过,下面给出了我使用的代码 foreach()

提交
<?php if(isset($_POST['submit'])){

echo $exp=$_POST['expertise'];
$sq=mysql_fetch_assoc(mysql_query("select distinct(requirement_id) from requirement where label_value='$exp'"));

foreach($sq as $ii){
echo $query1 = "SELECT u.`users_id`, u.`name`, u.`email`, u.`phone`, re.`label_name`, re.`label_value`, re.`requirement_id`, re.`date` FROM users u INNER JOIN requirement re ON u.`users_id`=re.`users_id` WHERE re.`requirement_id`='$ii'";

$query=mysql_query($query1);

$resultArr = array(); //to store query result
while($row=mysql_fetch_assoc($query))
{
$resultArr[] = $row;
}
//print_r($resultArr);
?>
<table class="table table-hover">
<tbody>
<?php
$tempUserID = "";
$tempEmail = "";
$tempPhone = "";
$tempReqID = 0;
for($i=0;$i<count($resultArr);$i++)
{
//if user id is blank, assign temporary values we need only for one time.
if($tempUserID=="")
{
$tempUserID = $resultArr[$i]['users_id'];
$tempEmail = $resultArr[$i]['email'];
$tempPhone = $resultArr[$i]['phone'];
$tempReqID = $resultArr[$i]['requirement_id'];
//printing first row
?>
<tr>
<td>
<div class="row" style="background: #00ACFF; ">
<p style="padding: 10px;margin: 0;color: white;">
<i class="fa fa-user"></i>
<strong> <?=$resultArr[$i]['name']?> </strong>
<span style="font-size:85%;"><?=$resultArr[$i]['users_id']?>000<?=$tempReqID?></span>
<span class="pull-right">
<i class="fa fa-clock-o"></i> <?=$resultArr[$i]['date']?>
</span>
</p>
</div>
<div class="row" style="background: #EDFEAF; min-height:80px;">
*Looking For<br>->
<?php
}
//ok
if($tempUserID == $resultArr[$i]['users_id'] && $tempReqID==$resultArr[$i]['requirement_id'])
{
//printing label_name and label_value if users_id is equal to the tempuserid
?>

<br>
<?=$resultArr[$i]['label_name']?>: <?=$resultArr[$i]['label_value']?>
<br>

<?php
}
else
{
//if users_id is not equal to the previous one, we will close the first row(i.e.<tr>) and start a new one
?>
</div>
<div class="row" style="background: #00ACFF; ">
<p style="padding: 10px;margin: 0;color: white;">

<i class="fa fa-envelope"></i>&nbsp;<?php echo $email = substr_replace($tempEmail,"xxxxxxxxxx",3,10);?>
<!--<i class="fa fa-envelope"></i> <?php //$tempEmail?>-->
<i class="fa fa-mobile" style="margin-left:20px"></i>
<strong><?php echo $var1 =substr_replace($tempPhone, str_repeat("X", 6), 2, 6);?> </strong>

<span class="pull-right">
<a class="btn btn-default btn-xs" href="#">
View @&nbsp;&nbsp;&nbsp;
<i class="fa fa-circle-thin"></i> 12pt
</a>
</span>
</p>
</div>
</td>
</tr>
<?php
//since the users_id is not equal to the previous row, which means that data about new user is available, we will assign new values to temporary variables and start a new table row.
$tempUserID = $resultArr[$i]['users_id'];
$tempEmail = $resultArr[$i]['email'];
$tempPhone = $resultArr[$i]['phone'];
$tempReqID = $resultArr[$i]['requirement_id'];
?>
<tr>
<td>
<div class="row" style="background: #00ACFF; ">
<p style="padding: 10px;margin: 0;color: white;">
<i class="fa fa-user"></i>
<strong> <?=$resultArr[$i]['name']?> </strong>
<span style="font-size:85%;"><?=$resultArr[$i]['users_id']?>000<?=$tempReqID?></span>
<span class="pull-right">
<i class="fa fa-clock-o"></i> <?=$resultArr[$i]['date']?>
</span>
</p>
</div>
<!--the edited part -->
<div class="row" style="background: #EDFEAF; min-height:80px;">
*Looking For<br>->
<br>
<?=$resultArr[$i]['label_name']?>: <?=$resultArr[$i]['label_value']?>
<br>
<?php
}
}
?>
<!--we will close the table row if current row is the last one in the result-->
<div class="row" style="background: #00ACFF; ">
<p style="padding: 10px;margin: 0;color: white;">

<i class="fa fa-envelope"></i> <?php echo $email = substr_replace($tempEmail,"xxxxxxxxxx",3,10);?>
<i class="fa fa-mobile" style="margin-left:20px"></i>
<strong> <?php echo $var1 =substr_replace($tempPhone, str_repeat("X", 6), 2, 6); ?></strong>

<span class="pull-right">
<a class="btn btn-default btn-xs" href="#">
View @&nbsp;&nbsp;&nbsp;
<i class="fa fa-circle-thin"></i> 12pt
</a>
</span>
</p>
</div>
</td>
</tr>





</div><!--/col-9-->
</tbody>
</table>

<?php } } ?>

最佳答案

首先,不要使用 mysql_*,请参阅 this发布以获取更多信息。

除此之外,您不能将用户数据直接粘贴到查询中,这是不安全的,想象一下有人输入类似“1;删除表要求”的内容。

为了回答您的问题,您无法将数组直接粘贴到查询中,因此 $exp 不是数组(除非您现在收到错误)。

如果您实际上有一个数组作为 $exp,请使用 foreach 循环将数组重写为字符串,这样您就会得到类似的内容

select distinct(requirement_id) from requirement where label_value IN(1,2,3)

关于php - 我在搜索过程中只得到一个结果,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36006442/

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