Jump to content

Mutil-dimentional array


rashmi_k28

Recommended Posts

function getValues(){
$param=array("ban","cpu","mem");
$array=array();

if($option1="ban"){
$sql=mysql_query("select time,ban from table1");
while($row=mysql_fetch_assoc){

$array['time'][]=$row[0];
$array['ban'][]=$row[1];
}
}

if($option1="cpu"){
$sql=mysql_query("select time,cpu from table2");
while($row=mysql_fetch_assoc){

$array['time'][]=$row[0];
$array['cpu'][]=$row[1];
}
}

if($option1="mem"){
$sql=mysql_query("select time,mem from table3");
while($row=mysql_fetch_assoc){

$array['time'][]=$row[0];
$array['mem'][]=$row[1];
}

}


}

 

 

 

The $option1 values should take and query the sql statements only which is present in the array $param. If the $param contains only ban and cpu, the $option1 should not query the option if($option1="mem")

 

 

 

How to get the output in the below format.

Please help me.

 

 

$array = array(

                'Ban' => array(

                                '12:00:12'|'168',

                                '12:45:20'|'34324',

                                '12:34:45'|'35435',

                        ),

                'Cpu' => array(

                                ''12:00:15'|'46456',

                                '12:20:12'|'34534',

                                '12:40:12'|'4645',

                        ),

                'Mem' => array(

                                '12:04:12'|'454',

                                '10:00:12'|'34',

                                '08:00:12'|'6',

                        ),

 

        );

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/128320-mutil-dimentional-array/
Share on other sites

I think this should do it

<?php
function getValues()
{
$param=array();
$param["ban"] = "table1";
$param["cpu"] = "table2";
$param["mem"] = "table3";
$data = array();

foreach($param as $key=>$value)
{
	$sql=mysql_query("select time,".$key." from ".$value);
	while($row=mysql_fetch_assoc($sql))
	{
		$data[$key][] = $row['time']."|".$row[$key];
	}
}

return $data;
}
?>

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.