php - PDO prepare NOT IN or <> multi language -


for few hours struggling make work. ok have 2 languages in first case in url no variable ?lang= base language , function checks language variable lang,do, if variable in url exists,and whatever value is, set global variable $lang "en" else null. got in database have column lang , need data out of it. public variable if true means need subjects pulic , in database column "visible" value 2. if not visible value 1.

  1. get public items visible don't have value "en" in row lang
  2. get public items visible if lang != null (if in row lang value "en"
  3. get items if public == false && lang == null rows got visible 2 , lang column empty
  4. get items if public == false && lang != null items if in column lang value "en". that's need. mysteriously not working. code.

    function get_all_subjects($public = true,$lang = null){ $db = connect_db(); $query = "select * ";  $query .= "from subjects "; if($public && $lang == null){     $query .= "where visible =:visible ";     $query .= "and lang =:lang "; }elseif($public && $lang != null){     $query .= "where visible =:visible ";     $query .= "and lang =:lang "; }elseif(!$public && $lang != null){     $query .= "where lang =:lang "; }elseif(!$public && $lang == null){     $query .= "and lang =:lang "; } $stmt = $db->prepare($query); if($public && $lang == null){     $stmt->bindvalue(':visible', 2, pdo::param_int);     $stmt->bindparam(':lang',$lang, pdo::param_str); }elseif($public && $lang != null){     $stmt->bindvalue(':visible', 2, pdo::param_int);     $stmt->bindparam(':lang',$lang, pdo::param_str); }elseif(!$public && $lang != null){     $stmt->bindparam(':lang',$lang, pdo::param_str); }elseif(!$public && $lang == null){     $stmt->bindparam(':lang',$lang, pdo::param_str); }  if($stmt->execute()){ return $stmt;  }else{ return null; } } 

    i think in need put in not in :lang or <>:lang or != don't now... nothing works head hurts , tired.

edited. works public , !public "versions" in "en". in base language public = true , public = false got error fatal error: call member function fetch() on non-object in other function call on. on line 2 i think know.. need not in, in first if statement :lang. how? $all_subjects = get_all_subjects($public,$lang); $subject = $all_subjects->fetch(pdo::fetch_assoc)

solved. bit of study mysql

function get_all_subjects($public = true,$lang = null){     $db = connect_db();     $query = "select * ";      $query .= "from subjects ";     if($public && $lang == null){         $query .= "where not lang =:lang ";         $query .= " , visible =:visible ";     }elseif($public && $lang != null){         $query .= "where visible =:visible ";         $query .= "and lang =:lang ";     }elseif(!$public && $lang != null){         $query .= "where lang =:lang ";     }elseif(!$public && $lang == null){         $query .= " not lang =:lang ";     }     $stmt = $db->prepare($query);     if($public && $lang == null){         $stmt->bindvalue(':visible', 2, pdo::param_int);         $stmt->bindvalue(':lang','en', pdo::param_str);     }elseif($public && $lang != null){         $stmt->bindvalue(':visible', 2, pdo::param_int);         $stmt->bindparam(':lang',$lang, pdo::param_str);     }elseif(!$public && $lang != null){         $stmt->bindparam(':lang',$lang, pdo::param_str);     }elseif(!$public && $lang == null){         $stmt->bindvalue(':lang','en', pdo::param_str);     } if($stmt->execute()){     return $stmt; }else{     return null; } 

}


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -