Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Blog
Books
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links






 
 

SPONSORS



 
 

Operating system wars

This is a follow up from our browser wars script . We will check for Windows and the Mac operating sytems . The only script that differs is the script that displays the stats on the screen , displaystats.php . Here is the updated script to check for operating sytems

<?php
// Connect to the database
$db = mysql_connect("localhost","username","password");
mysql_select_db("browser",$db);
//get the total hits and store in $total
$sql = "SELECT * FROM browser";
$results = mysql_query($sql);
$total = mysql_num_rows($results);
//for debugging to check the total hits
//echo $total;
//get the windows total
$sql = "SELECT * FROM browser WHERE browser LIKE ('%WIN%')";
$results = mysql_query($sql);
$win = mysql_num_rows($results);
//for debugging to check the windows hits
//echo $win;
//get the mac total
$mac = $total - $win;
//work out hits as percentages
$winhits = ($mac/($mac + $win));
$machits = ($win/($mac + $win));
//generate graphics
function graphgen ( $blueval , $redval )
{
$redstats = round($blueval*100,1 );
$bluestats = round($redval*100,1 );
$blueval = ($blueval * 200);
$redval = ($redval * 200);
echo"
<table><tr><td align=\"center\">$bluestats%</td><td>
<img src= \"gdbars.php?bluevalue=$blueval&redvalue=$redval\">
</td><td align= \" center \" >$redstats%</td></tr></table>" ;
}
echo"
<tr><td align=\"center\">
<table bgcolor=\"#cccccc\">
<tr><td align=\"center\" valign=\"bottom\">" ;
graphgen ($winhits ,$machits);
echo "</td></tr><tr><td align=\"center\" align=\"center\">" ;
echo "Windows Vs Mac" ;
echo "</td></tr></table>";
?>

Here is the output , note we only have Windows available so we should expect 100% for Windows , lets see what we get.

Just as we expected .

operating systems