gpt4 book ai didi

php - 如果其他条件不起作用

转载 作者:行者123 更新时间:2023-11-29 22:46:06 26 4
gpt4 key购买 nike

我需要什么

  • 我需要一些东西,比如当计数为零时,控制流应该转移到其他条件。

php代码

$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) //
}

输出:

  • 当获取数据库的计数为零时,它将把控制流转移到 else 循环。
  • 它应该是 else 循环中的数据。

最佳答案

$num=mysql_num_rows($resul); 不存在,正确名称为 mysql_num_rows,带下划线。

$num = mysql_num_rows($resul);
^

else 分支位于错误括号后面(与 if(isset($city) && isset($country)) 条件接近的分支)。

if(isset($city) && isset($country)) {
...
if ($num > 0) {
...
} else {
// $num == 0
}
} // you have ELSE branch here

关于php - 如果其他条件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29116715/

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