【发布时间】:2016-01-18 10:43:12
【问题描述】:
我正在为PHP 中的android 开发人员创建一个API,他想在其中从数据库中删除一些值并希望在此之后显示一条消息。
现在的问题是该数据已成功删除,但此 API 在完成该过程后始终显示其他部分消息。如果我删除 else 部分,它会返回 null,这会使 android 应用程序崩溃。所以我只想给android开发者一个正确的json消息
这是我正在尝试的代码
if($clear_my_property == "yes" && $clear_my_requirement == "yes" && $all_of_these == "yes" && $user_name_id == $user_name_id1)
{
$tables_count = array("property_for_sale","property_for_rent","cpo_post_requirements");
foreach($tables_count as $table_count)
{
$user_count = mysql_query("select * from $table_count where user_name = '$user_name'");
$total_user_count = mysql_num_rows($user_count);
if($total_user_count > 0)
{
$tables_data = array("property_for_sale","property_for_rent","cpo_post_requirements");
foreach($tables_data as $table_data)
{
$user_sql = mysql_query("delete from $table_data where user_name='$user_name'");
if($user_sql)
{
$response['success'] = 1;
$response['user']['error_msg'] = 'Clear Successfully All History!';
}
}
}
else
{
$response['success'] = 0;
$response['user']['error_msg'] = 'Record Not Found!';
}
}
}
我知道这个逻辑有问题。但我需要专家建议我的逻辑哪里错了,我必须做些什么才能让它成功
【问题讨论】:
-
试试这个: if($total_user_count > 0) { $tables_data = array("property_for_sale","property_for_rent","cpo_post_requirements"); foreach($tables_data as $table_data) { $user_sql = mysql_query("从 $table_data 中删除 user_name='$user_name'"); } $response['成功'] = 1; $response['user']['error_msg'] = '成功清除所有历史记录!'; } 并删除 else 部分