Is it possible to create csv file from this?
this table in database look like the one echo below
id | category| supplier | price 1 | A | supplier1 | 5 2 | B | supplier2 | 3 3 | B | supplier1 | 7 4 | C | supplier3 | 6 5 | C | supplier1 | 2 6 | B | supplier3 | 9
<?php
session_start();
$host = "localhost";
$user = "root";
$pass = "";
$con = mysql_connect($host,$user,$pass);
if($con)
{
$db = mysql_select_db('stocks');
if($db)
{}
else
{
echo "No Database Found! " ;
}
}
else
{
echo "Failed to Connect! ";
}
?>
<table>
<tr>
<th>Category</th>
<th>Stock</th>
<th>Percentage</th>
</tr>
<?php
$total=6;
$q="SELECT id,name,supplier,price,COUNT(*) FROM items GROUP BY supplier";
$r = mysql_query($q);
while($row = mysql_fetch_array($r))
{
$ratio=($row['COUNT(*)']/$total)*(100);
echo "<tr>";
echo "<td>" . $row['category'] . "</td>";
echo "<td>" . $row['COUNT(*)'] . "</td>";
echo "<td>" . round($ratio,2). "%</td>";
echo "</tr>";
}
echo "</table>";
?>
How can I put that in csv?
I only know to do it for select all in table.
Category Stock Percentage A 1 16.67% B 3 50% C 2 33.33%