Set allowed value of a list field depending on the URL
You're making this a little more convoluted than it needs be; the core arg() function can parse out the path and get the 4th element; the query is also broke (condition() is passed a string literal instead of variable &amp; it's missing aliasing argument); lastly you could help readability with a switch control. 

  //fields() needs an alias argument $group_id can be pulled from arg()
  $og_type = db_select('node','n') 
    -&gt;fields('n', array('type'))
    -&gt;condition('nid', arg(3), '=')
    -&gt;execute()-&gt;fetchField();