width $tr = ''; $row = $tr; $td = '%s'; // sprintf() requires %% to get % // loop over entries and display in rows of size $size $i = 0; // $i counts table rows foreach($array as $e){ $row .= sprintf($td,$e); $i++; // end of row; close it and open a new one: if(!($i % $size)) {$row .= "$tr";} } // pad out remaining cells with blanks while($i % $size){ $row .= sprintf($td,' '); $i++; } // add if necessary $end_tr_len = strlen($tr)-1; if(substr($row,$end_tr_len) != $tr) { $row .= ''; } else { $row = substr($row,0,$end_tr_len); } return $row; } $rocquery = "select roc_type,roc_serial,sm_layer,sm_stack from roc where "; $rocquery .= "sm_id=$sm_id order by sm_stack,sm_layer"; $rocres = pg_query($rocquery) or die ("
ERROR: cannot execute query ".$rocquery); if(pg_num_rows($rocres) != 0){ $DCSPars = array('Stack','Layer','DCS','MAC address'); $NumPars = sizeof($DCSPars); echo ''; echo Array_to_HTML_Table($DCSPars,$NumPars); while ($rocrow = pg_fetch_array($rocres)){ extract($rocrow); $query = "select dcs_id,mac from dcs where rob_id in ("; $query .= "select rob_id from rob where "; $query .= "roc_type='".$roc_type."' and roc_serial=$roc_serial) order by dcs_id"; $res = pg_query($query) or die ("
ERROR: cannot execute query ".$query); if(pg_num_rows($res) != 0){ while ($row = pg_fetch_array($res)){ extract($row); $mac = GetMacAddress($dcs_id); $new_id = sprintf("%04d",$dcs_id); $CurrentDCS = array($sm_stack,$sm_layer,$new_id,$mac); echo Array_to_HTML_Table($CurrentDCS,$NumPars); } } else die ("
ERROR: no DCS records retieved!"); } echo '
'; } else die ("
ERROR: no ROC records retieved!"); ?>