Jump to content

Passing array values


maliary

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/60933-passing-array-values/
Share on other sites

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;}

}

}

Link to comment
https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303206
Share on other sites

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
	}
}

Link to comment
https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303346
Share on other sites

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

}

}

 

 

Link to comment
https://forums.phpfreaks.com/topic/60933-passing-array-values/#findComment-303816
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.