maliary Posted July 20, 2007 Share Posted July 20, 2007 Hi, I am trying to pass an array into a function but it keeps giving me errors. this is the array $group = array("man","woman"); This is where i pass it from $tparams=&$lab_obj->TestParamsShow($group ) This is the function function TestParamsShow($group_id=''){ global $db; while (list($key, $val) = each($group_id)) { echo "$val"; $this->sql="SELECT * FROM $this->tb_test_param WHERE group_id ='$val' AND status NOT IN ($this->dead_stat) ORDER BY torder ASC"; if($this->tparams=$db->Execute($this->sql)){ if($this->rec_count=$this->tparams->RecordCount()) { return $this->tparams; } else {return FALSE;} }else {return FALSE;} } } The echo "$val"; only outputs the first value in the array - man. Why? Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/ Share on other sites More sharing options...
clearstatcache Posted July 20, 2007 Share Posted July 20, 2007 think, 8 wud be better if u used foreach() instead of while() function TestParamsShow($group_id=''){ global $db; foreach( $group_id as $key => $val ) { echo "$val"; $this->sql="SELECT * FROM $this->tb_test_param WHERE group_id ='$val' AND status NOT IN ($this->dead_stat) ORDER BY torder ASC"; if($this->tparams=$db->Execute($this->sql)){ if($this->rec_count=$this->tparams->RecordCount()) { return $this->tparams; } else {return FALSE;} }else {return FALSE;} } } Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303206 Share on other sites More sharing options...
maliary Posted July 20, 2007 Author Share Posted July 20, 2007 I've used it,It still only gets the first value. It's also a bit buggy, (sorry i should have mentioned this in the first post) It prints out man twice. this is the out put - man man Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303221 Share on other sites More sharing options...
sasa Posted July 20, 2007 Share Posted July 20, 2007 when function return something function stop Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303232 Share on other sites More sharing options...
maliary Posted July 20, 2007 Author Share Posted July 20, 2007 How do I function stop? Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303245 Share on other sites More sharing options...
sasa Posted July 20, 2007 Share Posted July 20, 2007 function TestParamsShow($group_id=''){ global $db; while (list($key, $val) = each($group_id)) { echo "$val"; $this->sql="SELECT * FROM $this->tb_test_param WHERE group_id ='$val' AND status NOT IN ($this->dead_stat) ORDER BY torder ASC"; if($this->tparams=$db->Execute($this->sql)){ if($this->rec_count=$this->tparams->RecordCount()) { return $this->tparams; // in 1st pass one of this 3 lines return something and } else {return FALSE;} // function end }else {return FALSE;} // newer go to 2nd pass } } Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303346 Share on other sites More sharing options...
clearstatcache Posted July 21, 2007 Share Posted July 21, 2007 ryt....i overllok ur return.... if u want to go to the rest of the array instead of returning false, used continue... while (list($key, $val) = each($group_id)) { echo "$val"; $this->sql="SELECT * FROM $this->tb_test_param WHERE group_id ='$val' AND status NOT IN ($this->dead_stat) ORDER BY torder ASC"; if($this->tparams=$db->Execute($this->sql)){ if($this->rec_count=$this->tparams->RecordCount()) { return $this->tparams; // in 1st pass one of this 3 lines return something and } else continue; // function end }else continue; // newer go to 2nd pass } } Quote Link to comment https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.