ive spent 2 days just to make a simple table to auto sum, something like this in php/mysql:
qty rate amount balance
2 1000 2000 2000
3 1500 4500 6500
_____________________________________
the problem i faced is how can i get the balance amount
can anybody help?
300
can anybody helpppppp!!!!!
how to
Mysql Query:
create table stock(
sid int(11) NOT NULL auto_increment,
`date` date NOT NULL,
company varchar(20) NOT NULL,
sub_cat varchar(30) NOT NULL,
model varchar(50) NOT NULL,
qty int(10) NOT NULL,
rate int(30) NOT NULL,
remarks varchar(500),
primary key(`sid`)
);
_____________________________
PHP Code:
<?php
$query = 'SELECT sid, date, company, sub_cat, model, qty, rate, rate*qty AS amount FROM
stock';
$result = mysql_query($query, $con) or die(mysql_error($con));
while ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<tr>';
echo '<td>'.$sid.'</td>';
echo '<td>'.$date.'</td>';
echo '<td>'.$company.'</td>';
echo '<td>'.$sub_cat.'</td>';
echo '<td>'.$model.'</td>';
echo '<td>'.$qty.'</td>';
echo '<td>'.$rate.'</td>';
echo '<td>'.$amount.'</td>';
echo '<td>'.$remarks.'</td>';
}
?>
now i want 1 more column named 'BALANCE' to show the balance amount as shown in the previous post
qty rate amount balance
2 1000 2000 2000
3 1500 4500 6500
_____________________________________
the problem i faced is how can i get the balance amount
can anybody help?
300
can anybody helpppppp!!!!!
how to
Mysql Query:
create table stock(
sid int(11) NOT NULL auto_increment,
`date` date NOT NULL,
company varchar(20) NOT NULL,
sub_cat varchar(30) NOT NULL,
model varchar(50) NOT NULL,
qty int(10) NOT NULL,
rate int(30) NOT NULL,
remarks varchar(500),
primary key(`sid`)
);
_____________________________
PHP Code:
<?php
$query = 'SELECT sid, date, company, sub_cat, model, qty, rate, rate*qty AS amount FROM
stock';
$result = mysql_query($query, $con) or die(mysql_error($con));
while ($row = mysql_fetch_assoc($result)) {
extract($row);
echo '<tr>';
echo '<td>'.$sid.'</td>';
echo '<td>'.$date.'</td>';
echo '<td>'.$company.'</td>';
echo '<td>'.$sub_cat.'</td>';
echo '<td>'.$model.'</td>';
echo '<td>'.$qty.'</td>';
echo '<td>'.$rate.'</td>';
echo '<td>'.$amount.'</td>';
echo '<td>'.$remarks.'</td>';
}
?>
now i want 1 more column named 'BALANCE' to show the balance amount as shown in the previous post