rashmi_k28 Posted August 29, 2008 Share Posted August 29, 2008 Hi, Suppose one $centre_name has two nodes and the values are fetched from table1 and pushed into the array. When the function is called when i print the values using centre name and node name 4 times the values are printed. Please tell me how to push the data into the array and when called only the single value has to be printed. for($i=0;$i<=count($node);$i++){ foreach($node as $node){ print $cent['JNU']['master'][$i]; } the output is got is 0(1)(1)0(1)(1)PHP Notice: Undefined offset: 1 in /var/www/html/ instead of 3 values like 0(1)(1). Array ( [0] => 0 [JNU] => Array ( [master.jnu.ac.in] => Array ( [0] => 0(1)(1) ) [cluster.jnu.ac.in] => Array ( [0] => 0(1)(1) ) ) ) function centreagg($centre_name){ $centreaggregate = array(0); $sql = "select distinct(node) from master_table where centre_name='".$centre_name."')"; $node = array(); $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { array_push($node,$row[0]); } $q=0; foreach($node as $_) { $value = array(0); $sql_net_perf = "select * from table1 where node = '".$_."' group by node"; //$sql_net_perf = "select count(*),cm.no_of_nodes,cm.total_nodes from nodes_details_cur nd, cluster_master cm where nd.head_node = cm.head_node and status = 0 and nd.head_node = '".$_."' group by nd.head_node"; $result = mysql_query($sql_net_perf); while($row = mysql_fetch_array($result)) { $value[0]=$row[1].'('.$row[0].')'.'('.$row[0].')'; } $centrevalues[$node[$q++]]=$value; } $centreaggregate[$centre_name]=$centrevalues; return $centreaggregate; } $cent=($centre_name); $node=array('master','cluster'); for($i=0;$i<=count($node);$i++){ foreach($node as $nod){ print $cent[$centre_name][$nod][$i]; //print $cent[$centre_name][$head][$i]; } } Link to comment https://forums.phpfreaks.com/topic/121829-function/ Share on other sites More sharing options...
rashmi_k28 Posted September 5, 2008 Author Share Posted September 5, 2008 function centreagg($centre_name){ $centrevalues = array(0); $sql = "select distinct(node) from master_table where centre_name='".$centre_name."')"; $node = array(); $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { array_push($node,$row[0]); } $q=0; foreach($node as $_) { $value = array(0); $sql_net_perf = "select * from table1 where node = '".$_."' group by node"; //$sql_net_perf = "select count(*),cm.no_of_nodes,cm.total_nodes from nodes_details_cur nd, cluster_master cm where nd.head_node = cm.head_node and status = 0 and nd.head_node = '".$_."' group by nd.head_node"; $result = mysql_query($sql_net_perf); while($row = mysql_fetch_array($result)) { $value[0]=$row[1].'('.$row[0].')'.'('.$row[0].')'; } $centrevalues[$node[$q++]]=$value; } return $centreaggregate; } $centreComputegridfs= updowntotal($center_name); $node=array('master','cluster'); for($j=0;$j<count($centreComputegridfs);$j++){ $i=0; foreach($head_node as $head){ print $centreComputegridfs[$head][$i]; } $i++; } Hi, I have a function which returns the values based on the centre_name. When the count is greater than 1 the for the master and cluster, it has to print like this. print $centreComputegridfs['master'][0]; print $centreComputegridfs['cluster'][1]; At present it is printing when only nodde as master is selected it print's cluster node value also. How to avoid and print only based on head_node. Link to comment https://forums.phpfreaks.com/topic/121829-function/#findComment-634340 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.