为了账号安全,请及时绑定邮箱和手机立即绑定

PHP,如何扩展我的代码以检查给定位置是否未包含在数据库中?

PHP,如何扩展我的代码以检查给定位置是否未包含在数据库中?

PHP
翻阅古今 2023-04-15 17:38:20
从现有位置获取数据效果很好,但不检查错误。class Information extends DB {function get(){$loc=$_GET['loc'];  return $this->select("SELECT location, MAX(population), MAX(total_deaths_per_million),  MAX(total_cases), MAX(total_deaths), MAX(total_cases_per_million) FROM corona WHERE location= '$loc'");}}
查看完整描述

1 回答

?
哔哔one

TA贡献1854条经验 获得超8个赞

可以先查询位置。我还没有运行它来测试它,但是像这样的东西应该可以解决问题


class Information extends DB {

function get(){

$loc=$_GET['loc'];    


$locationResults = $this->select("SELECT location FROM corona WHERE location= '$loc'");


if ($locationResults->num_rows == 0) {

    echo "If the number of rows returned is equal to 0, then there's no locations for the location the user gave";      

    } else {

       return $this->select("SELECT location, MAX(population), MAX(total_deaths_per_million),  MAX(total_cases), MAX(total_deaths), MAX(total_cases_per_million) FROM corona WHERE location= '$loc'");


    }// end else

  }//end function

}//end class


查看完整回答
反对 回复 2023-04-15
  • 1 回答
  • 0 关注
  • 109 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信