Php 如何通过比较值从while语句中选择特定数据?
这个标题几乎是不言自明的。我试图从while语句中选择一个特定的计划,方法是将值比较在一起并返回一个可以与jQuery一起使用的数组中的计划详细信息Php 如何通过比较值从while语句中选择特定数据?,php,Php,这个标题几乎是不言自明的。我试图从while语句中选择一个特定的计划,方法是将值比较在一起并返回一个可以与jQuery一起使用的数组中的计划详细信息 $compareme = some integer; while($plan = mysqli_fetch_assoc($resultplans)) { $finalpricing = round($plan['price']); $planname = $plan['name']; $plandescription = $plan['desc
$compareme = some integer;
while($plan = mysqli_fetch_assoc($resultplans)) {
$finalpricing = round($plan['price']);
$planname = $plan['name'];
$plandescription = $plan['description']'
if($compareme == $finalpricing){
//select the plan with the same pricing as $compareme
//create json array that can be used with jQuery
$planArray = array(
'planName' => $planname,
'planPrice' => $finalpricing,
'planDescription' => $plandescription
);
//encode in json
header('Content-Type: application/json');
echo json_encode($planArray);
}
} <-- end of while loop-->
$compareme=某个整数;
而($plan=mysqli\u fetch\u assoc($resultplan)){
$finalpricing=四舍五入($plan['price']);
$planname=$plan['name'];
$plandescription=$plan['description']'
如果($compareme==$finalpricing){
//选择与$compareme定价相同的计划
//创建可与jQuery一起使用的json数组
$planArray=array(
“planName”=>$planName,
“计划价格”=>$finalpricing,
“planDescription”=>$planDescription
);
//用json编码
标题('Content-Type:application/json');
echo json_编码($planArray);
}
}
现在让我们假设两个计划A和B以相同的价格返回。有没有办法只选择一个计划?选择哪一个并不重要。我只需要返回一个。添加一个
中断代码>在echo json_encode($planArray)之后代码>将退出while循环
echo json_encode($planArray);
break ;
如果在查询的Where子句中使用$comparame
变量会更好