Location: PHPKode > scripts > php virtual table > phpvirtualtable-alpha-0.04/vt/example3-vt.php
<?php
//filename: example3-vt.php
include_once "vt.php";
?>

<html>
<body>
<?php
//
$vt=new VirTable("","Item","Quantity","Unit Price","Total");

if($_POST["post_req"]=="true" && $_POST["saveCSV"]=="Save as CSV")
	{
	$vt->save_as_csv("csv-data/mytable.csv");
	}

if($_POST["post_req"]=="true" && $_POST["item"]!="" && $_POST["unit_price"]!="" && $_POST["quantity"]!="")
	{
		$price=0;
		$price=$_POST["unit_price"] * $_POST["quantity"];
		$vt->add_row('1',$_POST["item"],$_POST["quantity"],$_POST["unit_price"],$price);
	}
?>
<form method="POST" name="frm_product" action="">
<input type="hidden" name="post_req" value="true">
<table><tr><td>Select Item</td><td>
<select style="align:right;width:200px" name="item">
	<option selected>Not Selected</option>
	<option>Pen</option>
	<option>Paper</option>
	<option>Clip</option>
	</select></td><tr><td>Unit Price</td><td>
<select style="width:200px" name="unit_price">
	<option selected>Not Selected</option>
	<option>50</option>
	<option>100</option>
	<option>150</option>
	</select></td><tr><td>Quantity</td><td>
<input type="text" name="quantity" value="" style="width:200px">
</td></tr><tr><td align="right" colspan=2>
<input type="submit" name="saveCSV" value="Save as CSV">
<input type="submit" name="submit" value="Add This Item">
</td></tr></table>
<?php $vt->link_to_form();?>
</form>

<?php 
$vt->set_font_family("courier");
$vt->set_border_type("solid");
$vt->set_border_width("1px");
$vt->set_header_bgcolor("#8B6914");
$vt->set_even_row_color("#FFCD70");
$vt->show();
echo "<strong>Total =".$vt->sum(4)." Taka</strong><br/>";
//echo $vt->usage();
echo "<hr>";
echo "<strong><i>VirTable::fetch_record()</i></strong> Example-<br/>
Note:row starts from 0 and column starts from 1<br/>
<hr>";
for($r=0;$r<($vt->get_num_of_rows());$r++)
	{
	echo "|";
	for($c=1;$c<($vt->get_num_of_columns());$c++)
		{
		echo $vt->fetch_record($r,$c);
		echo "|";
		}
	echo "<br/>";
	}
echo "<strong>Number of rows available:".$vt->get_num_of_rows()."</strong>";
//$vt->usage();
?>
</body>
</html>
Return current item: php virtual table