Jump to content

splitting an array


tigomark

Recommended Posts

Ok I am trying to first get a list of stuff from an array created from a database.

 

I am able to do that in funcion LeftSelect but what I would like to do is separate out values that are grabbed from another call

and stored in $this->right_asset (vars 1,2,3,4)

the values then would populate the RightSelect

 

 

function LeftSelect(){
  $assets = loadAllStuff($getConnection);					
  $html = "<select name=\"target\" multiple=\"multiple\">\n";
    
  if(is_array($assets)){
    while(list ($key, $val) = each($assets)){
    	
    	if (in_array($val->id, $this->asset_select_right)) {
    		array_push($this->right_asset,($val->id, $val->stuff));
    	}else{
  $html .= sprintf("<option value=\"%d\">%s</option>\n",
      $val->id,
      htmlspecialchars($val->stuff));
      }
    }
  }
  $html .= "</select>\n";
  return($html);
}//assetSelect

function RightSelect(){
$html .=sprintf("
<select name=\"selected\" size=\"10\">");

if(is_array($this->right_stuff)){
while(list($key, $val) = each($this->right_stuff)){
 $html .= sprintf("<option value=\"%d\">%s</option>\n",
      $val->id,
      htmlspecialchars($val->stuff));	
}
}	
  	$html .=sprintf("</select>");	
  	
 return($html);
}

 

 

 

I am trying

 


if (in_array($val->id, $this->asset_select_right)) {
    		array_push($this->right_asset,($val->id, $val->stuff));

 

which is currently not working in the left. If I take out the if I do get the all of the values so that is working.

 

and the RightSelect is all fubar so I am kinda stuck.

 

Link to comment
https://forums.phpfreaks.com/topic/119795-splitting-an-array/
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.