<html>
<style>
  p{
	  font-family: Calibri;
	  color: black;
	  font-size: 20;
	}
td
{
	font-family: Calibri;
	color: black;
	font-size: 20;
	text-align:center;
	background-image:url('lightgray.jpg');
	background-size:100% 100%;
	background-repeat:no-repeat;
}
  </style>
<body style="background-image:url('gray.jpg');background-size:100% 100%;
background-repeat:no-repeat;">
<?php
//retrieving stock data and storing them in the database
$row = 1;
if (($handle = fopen("http://download.finance.yahoo.com/d/quotes.csv?s=AAPL+ADBE+AMZN+APOL+CSCO+CTSH+DELL+ERIC+GOOG+INFY+INTC+MSFT+ORCL+PROV+QCOM+SNDK+SWIR+VRTU+YHOO+ACCL+ACIW+BBSI+BITS+BLKB+BCSI+CVLT+CNQR+CCUR+PROJ+ELRC+ERII+FFDF+FNGN+GSBC+GRNB+GCBC+HALL+HBNK+HBHC+IBOC+JXSB+JFBC+KINS
+LKFN+SIRI+RAX+VVUS+DNDN+EBAY+RMBS&f=nsabp5p2v", "r")) !== FALSE)
{
	$con = mysql_connect("localhost:3306","","");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}
	mysql_select_db("test", $con);
	mysql_query("delete from stockdata");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
	{
		$num = count($data);
		$row++;
		for ($c=0; $c < $num; $c++) 
		{
		   $var[$c]= $data[$c] ;
		}
		//inserting fields into stockdata database
		mysql_query("INSERT INTO stockdata (company,symbol,ask,bid,price,stockchange,stockvolume)
		VALUES ('$var[0]','$var[1]','$var[2]','$var[3]','$var[4]','$var[5]','$var[6]')");
	}
	
    fclose($handle);
}
$active_result=mysql_query("select company,symbol,stockvolume from stockdata order by stockvolume desc;");
$i=0;
while($row = mysql_fetch_array($active_result))
{
	$active_comp[$i] = $row['company'];
	$active_sym[$i]=$row['symbol'];
	$active_vol[$i]=$row['stockvolume'];
	$i++;
}
echo "<p>";
echo "TOP 5 ACTIVE COMPANIES:</br>"; 
echo "<a href='help.php'>what's this?</a></br></br>";
echo "<table>";
echo "<tr>";
echo "<td>COMPANY</td>";
echo "<td>TICKER</td>";
echo "<td>VOLUME</td>";
echo "</tr>";
for($q=0;$q<5;$q++)
{
	echo "<tr>";
	echo "<td>$active_comp[$q]</td>";
	echo "<td>$active_sym[$q]</td>";
	echo "<td>$active_vol[$q]</td>";
	echo "</tr>";
	
}
echo "</table></br></br>";
?>
</body>
</html>