标题几乎不言自明。我试图从while语句中选择一个特定的计划,方法是将值进行比较,并在一个可以与jQuery一起使用的数组中返回计划的详细信息。
$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-->
现在让我们假设两个计划A和B以相同的价格返回。有没有办法只选择一个计划?选择哪一个并不重要。我只需要还一张。
发布于 2018-06-06 07:13:40
在echo json_encode($planArray);
后面添加一个break ;
,它将退出您的while循环。
echo json_encode($planArray);
break ;
https://stackoverflow.com/questions/50710008
复制相似问题