function comp_post_code($comp_post_code){
global $host, $dbname, $user, $pass;
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$DBH->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); ///*** for error handling
$STH = $DBH->prepare("SELECT * from uk_data where
comp_post_code like :comp_post_code and cat1 like :cat");
$STH->bindValue(':cat', "%$cat1%", PDO::PARAM_STR);
$STH->bindValue(':comp_post_code', "%$comp_post_code%", PDO::PARAM_STR);
$STH->execute();
$STH->setFetchMode(PDO::FETCH_ASSOC);
return $STH;
}
我有cat1到cat10 ..我想在不编写长代码的情况下获得数据输出
and comp_post_code like :comp_post_code and cat2 like :cat
and comp_post_code like :comp_post_code and cat3 like :cat
我有办法解决这个问题...我们可以编写 ong 代码并退出,但仍然想知道我们可以用其他方式吗?
表结构