Php 如果其他条件不起作用
我需要什么 我需要一些东西,比如当count为零时,控制流应该移到else条件。 php代码Php 如果其他条件不起作用,php,mysql,Php,Mysql,我需要什么 我需要一些东西,比如当count为零时,控制流应该移到else条件。 php代码 $lat = $_GET['lat']; $long = $_GET['lng']; /* new condition implemented */ $city=$_GET['city']; $country=$_GET['country']; if(isset($city) && isset($country)) { $query="SELECT city.
$lat = $_GET['lat'];
$long = $_GET['lng'];
/* new condition implemented */
$city=$_GET['city'];
$country=$_GET['country'];
if(isset($city) && isset($country))
{
$query="SELECT city.id cityid,city.name city_name
FROM city
WHERE city.name ='$city' limit 1";
$resul = mysql_query($query);
$num=mysql_numrows($resul);
$rows = mysql_fetch_row($resul);
/* check for the city name not matched with databse name */
if($num > 0)
{
/* now check for the upcoming events */
$q="SELECT *
FROM event
INNER JOIN event_edition ON event.id = event_edition.event
WHERE event.city =".$rows[0]."
AND event_edition.end_date >=NOW( )";
$r = mysql_query($q);
$nums=mysql_numrows($r);
$rowse = mysql_fetch_row($r);
/* check for count of upcoming events */
if($nums!=='' && $nums!=='null' && $nums >0)
{
$query2 = "SELECT city.id,city.name,city.url,country.id,country.name,country.phonecode,country.url,country.currency FROM city,country
WHERE city.id = ".$rows[0]." AND country.id = city.country";
$result = mysql_query($query2);
if($row = mysql_fetch_row($result))
{
$city = array();
$city['id'] = $row[0];
$city['text'] = $row[1];
$city['url'] = $row[2];
$country = array();
$country['id'] = $row[3];
$country['text'] = $row[4];
$country['phone_code'] = $row[5];
$country['country_url'] = $row[6];
$country['currency'] = $row[7];
$cityData = array();
$cityData['city'] = $city;
$cityData['country'] = $country;
echo json_encode($cityData);
}
}
}
}
else
{
//this should be true when count if($num > 0) //
}
输出:
当countfetch数据库为零时,它会将控制流转移到else循环。
它应该是else循环中的数据。
$num=mysql\u numrows$resu;不存在,正确的名称为mysql\u num\u行,带下划线
$num = mysql_num_rows($resul);
^
else分支位于坏括号后面,接近IFAsset$city和isset$country条件
if(isset($city) && isset($country)) {
...
if ($num > 0) {
...
} else {
// $num == 0
}
} // you have ELSE branch here
您需要使用两个赋值运算符来生成if条件。最里面的if条件只有一个赋值运算符
if($row= =mysql_fetch_row...)
{.........}
仍然处于if状态..我希望代码控件移到else中loop@user4041461:更新了我的代码,你把其他地方放在了一个不好的地方。我有相同的要求,比如如果城市国家存在,显示api的数据,显示其他数据,因此,第一个循环将始终为真,我需要使用任何其他逻辑将流从第一个条件移动到else。如果是country city的集合,则在父级中执行else。如果父级不使用不推荐的mysql_*API,则我希望将else放置在外。使用mysqli_u*或pdo要求,比如如果城市-国家/地区存在,则显示api的数据或显示其他数据,因此第一个循环将始终为真。我需要使用任何其他逻辑将流从第一个条件移动到其他条件。如果是国家/地区-城市的集合,则在父级中执行其他。如果是父级,则在父级中执行其他