Jump to content

print the function


rashmi_k28

Recommended Posts

Hi,

 

I have called a function

 

$centre=updown();

$nodes=array('aaa','bbb');

 

I have to print

 

$centre['aaa'][0];

$centre['bbb'][1];

 

 

When i use the code like this

all the values are printed for all the values in the array $nodes

 

for($i=0;$i<=count($centre);$i++){

foreach($nodes as $nod){

print $centre[$nod][$i];

}

}

 

 

If the nod='aaa' then only $centre[0] should be printed

 

If th nod='bbb' then only $centre[1] should be printed.

 

How to print the function based on this

 

 

Link to comment
https://forums.phpfreaks.com/topic/123208-print-the-function/
Share on other sites

If the nod='aaa' then only $centre[0] should be printed

 

If th nod='bbb' then only $centre[1] should be printed.

But you're looping through the $nodes array. Wouldn't $nod be "aaa" on the first looping and be "bbb" on the second looping?

 

<?php

$count_centre = count($centre);
$count_nodes = count($nodes);
$s = $b = -1;
while (++$s < $count_centre) {
     foreach ($nodes as $nod) {
          while (++$b < $count_nodes) {
               print $centre[$nod][$b];
          }
     }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/123208-print-the-function/#findComment-636314
Share on other sites

function updowntotal($center){

        $centrevalues = array();

         $sql = "select distinct(node) from `master_table`";
        $nodes = array();
        $result = mysql_query($sql);

        while($row = mysql_fetch_array($result))
        {
                array_push($nodes,$row[0]);
        }


                $q=0;
                foreach($nodes as $_)
                {
                        $value = array();
                        $sql_net_perf = "select field1,field2,field3 from `table_name` where node = '".$_."' ";
                        $result = mysql_query($sql_net_perf);

                        if($row = mysql_fetch_array($result))
                        {
                                 $value[0]=$row[0].'('.$row[1].')'.'('.$row[2].')';


                        }

                        $centrevalues[$nodes[$q++]]=$value;
                }
                

return $centrevalues;
}

 

 

When I call the function

 

$centreCom= updowntotal($center);

 

and print based on $nodes array which is called separately

$count_centre = count($centreCom);

$count_nodes = count($nodes);

$s = $b = -1;

while (++$s < $count_centre) {

    foreach ($nodes as $nod) {

          while (++$b < $count_nodes) {

              print $centreCom[$nod][$b];

          }

    }

}

 

 

For all the $nod $centreCom[0] is printed everywhere.

 

How to avoid it

Please help me

Link to comment
https://forums.phpfreaks.com/topic/123208-print-the-function/#findComment-637274
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.