Jump to content

Argument


rashmi_k28

Recommended Posts

Hi,

 

I have a array of $param and how to pass the values of $param to groupValues() function.

 

$param=array('bw','pkt','cpu');
$values = groupValues();

function groupValues(){

$value = array();

$sql = "select field1 from tabe1";
                        $result = mysql_query($sql);
                         while($row = mysql_fetch_array($result)){
                         $value['pkt'][] = $row[0];
}
$sql = "select field2 from tabe2";
                        $result = mysql_query($sql);
                         while($row = mysql_fetch_array($result)){
                         $value['bw'][] = $row[0];
}
$sql = "select field3 from tabe3";
                        $result = mysql_query($sql);
                         while($row = mysql_fetch_array($result)){
                         $value['cpu'][] = $row[0];
}
$sql = "select field4 from tabe4";
                        $result = mysql_query($sql);
                         while($row = mysql_fetch_array($result)){
                         $value['mem'][] = $row[0];
}
$sql = "select field5 from tabe5";
                        $result = mysql_query($sql);
                         while($row = mysql_fetch_array($result)){
                         $value['vmem'][] = $row[0];
}

return $value;
}

 

 

There are many queries inside the function.

 

How to query the function based on the array $param values passed to the function.

 

 

Link to comment
https://forums.phpfreaks.com/topic/129749-argument/
Share on other sites

Just modify this to fit your code...

 

$param = ('array1','array2','array3');

foreach($param as $value){

handleArray($value);

}

function handleArray($value){

if($value=="array1"){
QUERY FOR ARRAY1;
}elseif($value=="array2"){
QUERY FOR ARRAY2;
}elseif($value=="array3"){
QUERY FOR ARRAY3;
}else{
echo "ERROR";
}

}

Link to comment
https://forums.phpfreaks.com/topic/129749-argument/#findComment-672679
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.