Jump to content

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

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.