Page 2 of 2

Posted: Mon Feb 20, 2006 12:08 am
by kingconnections
OK here is my code:

Code: Select all

$patches = array();



// FETCH CURRENT YEAR PATCHES

while($row = mssql_fetch_array($result)) 

{ 

//echo "<td>" . $row["patch"] . "</td>"; 

$mspatch = $row["patch"];



$patches[] = $mspatch;

}

Posted: Mon Feb 20, 2006 12:18 am
by feyd

Code: Select all

$patches = array();



// FETCH CURRENT YEAR PATCHES

while($row = mssql_fetch_array($result)) 
{ 

//echo "<td>" . $row["patch"] . "</td>"; 
$patches[] = array($row['patch']);

}
What's the query being run?

Posted: Mon Feb 20, 2006 12:26 am
by kingconnections
here is the query and code...
edited cause wrong code was inserted.

Code: Select all

$query2 = "SELECT patch, COUNT(server) AS count FROM PatchStatus WHERE site = '$site'	AND status <> 'Patched' AND status <> 'Unsupported OS' and patch like '$patch' GROUP BY patch ORDER BY patch asc ";
	
$result2 = mssql_query($query2); 
$numRows = mssql_num_rows($result2); 

//$cols2 = array('MS06-001'=>array('1',),'MS06-007'=>array('8',),'MS06-008'=>array('50',));

$cols = array('patch_col'=>array('count_col'),);

while($row = mssql_fetch_array($result2)) 
{
    
    //echo "<td>".$row["patch"]."</td><td>" . $row["count"] . "</td>"; 
   
    $cols[$row["patch"]] = array($row["count"]);  
  
    
}

Posted: Mon Feb 20, 2006 12:30 am
by kingconnections
Even when I had this in there to load the array it didn't work.

Code: Select all

$cols[$row["patch"]] = array($row["count"]);

Posted: Mon Feb 20, 2006 12:42 am
by feyd
If you var_export($cols) afterward, what shows?

Posted: Mon Feb 20, 2006 1:44 am
by kingconnections
Seems like it is working now, I just forgot a ;. But I have another issue that I didn't realize until now, and that is that I need to make it a 3d array instead of a 2d array.

Is this right?

Code: Select all

foreach ($sitecodes as $site) {
//echo "<tr><td>$site";
$query2 = "SELECT  site, patch, COUNT(server) AS count FROM PatchStatus WHERE site = '$site' AND status <> 'Patched' AND status <> 'Unsupported OS' and patch like '$patch' GROUP BY patch ORDER BY patch asc ";
	
$result2 = mssql_query($query2); 
$numRows = mssql_num_rows($result2); 

//$cols2 = array('MS06-001'=>array('1',),'MS06-007'=>array('8',),'MS06-008'=>array('50',));

//$cols = array('patch_col'=>array('count_col'),);

	while($row = mssql_fetch_array($result2)) 
		{
    
    //echo "<td>".$row["patch"]."</td><td>" . $row["count"] . "</td>"; 
   
    		[b]$cols[$row["site"]] = array($row["patch"])=>array($row["count"]);  [/b]
      } 

echo "</tr>";
var_export($cols);
there is something wrong with the bold line, I get a
"Parse error: syntax error, unexpected T_DOUBLE_ARROW in d:\wwwroot\Patches\scripts\test.php on line 71"

Thanks a ton for your help guys. I really really am grateful.

Thanks

Dan

Posted: Mon Feb 20, 2006 1:55 am
by feyd
replace that line with the following

Code: Select all

// make sure the main index exists
if (!isset($cols[$row['site']]))
{
  $cols[$row['site']] = array();
}
$cols[$row['site']][$row['patch']] = array($row['count']);
[edit] fixed a little bug

Posted: Mon Feb 20, 2006 9:06 am
by kingconnections
Great!...... Thanks a ton... Next question



I am trying to make a table like so

site|patch1|patch2|patch3| and so on
loc1| 5 | 10 | 15 |
loc2| 2 | 11 |



the problem is that not every site has 3 patches that return in the sql query, infact there is no data in there for that record at all because it is not vulerable.

So how can i check to the 3d array and ensure that every site has every patch, and if the patch isn't there put it there and give the count a 0 value.

Unless you know a better way to display a blank.

I also need to know how I display the foreach loop to make each record go sideways like that.

here is what I have currently:

Code: Select all

//////////// output table 
//echo '<p>There are '.sizeof($cols)." Patches.</p>\n";


?>
/////////// list patches going sideways ---- this section works fine.
echo "<tr><th>Vulerable Patches</th></tr><tr><td>Site</td>";


foreach( $current_patchs as $patchs )
{
  echo "<td>".$patchs."<td></tr>";
 }
echo "<br><tr>";

/// list sites going across in site patch1(count), patch2(count)  -- this section does not work


foreach ( $cols as $site)
{
echo"<tr><td>$site</td></tr>";
}


</tr>
</table>
</body>
</html>

Posted: Mon Feb 20, 2006 9:25 am
by kingconnections
OK, I am getting close!

here is my updated code:

the problem is it displays in the correct format, just says Array in all the values
where the count should be, and also it still does not take into account for those
records that do not exisit.

Code: Select all

/////////// list patches going sideways
echo "<tr><th>Vulerable Patches</th></tr><tr><td>Site</td>";


foreach( $current_patchs as $patchs )
{
  echo "<td>".$patchs."</td></tr>";
 }
echo "<br><tr>";

///////////// list site and patch count going sideways......

foreach ( $cols as $site=>$patch)
{
echo"<tr><td>$site</td>";

foreach ( $cols as $patch=>$count)
{ 
}
foreach ($cols as $patch=>$count)
{
 echo "<td>   ".$count." </td>";
} 
echo "</tr>";


}

?>

</tr>
</table>
</body>
</html>