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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.