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

从现有位置获取数据效果很好,但不检查错误。


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'");

}

}


翻阅古今
浏览 110回答 1
1回答

哔哔one

可以先查询位置。我还没有运行它来测试它,但是像这样的东西应该可以解决问题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
打开App,查看更多内容
随时随地看视频慕课网APP