$sql = mysql_query("SELECT DISTINCT business_region FROM business WHERE business_category='occupation'");
// count the output amount
$businessCount = mysql_num_rows($sql);
if ($businessCount > 0) {
while ($row = mysql_fetch_array($sql)) {
$business_region = $row["business_region"];
$Region_view .= "display value";
}
}
这给出了以下结果:
密歇根州多伦多俄亥俄州曼彻斯特伦敦悉尼巴黎
我想选择仅 Ohio and London
作为变量值:
$Region_view .
也许我可以使用if else结构,但我无法让它工作。
即。我需要选择 仅Ohio, London
我可以使用联合MySQL语句来做到这一点,但它太慢了所以我需要并要求采用不同的方式。
答案 0 :(得分:1)
$sql = mysql_query("SELECT DISTINCT business_region FROM business WHERE business_category ='occupation'");
// count the output amount
$businessCount = mysql_num_rows($sql);
if ($businessCount > 0) {
while($row = mysql_fetch_array($sql)){
$business_region = $row["business_region"];
if ($business_region == 'Ohio' || $business_region == 'London') // added
$Region_view .= $business_region;//changed
}
}