Hi all,
I'm sorta new in this but I'm trying hard to learn, I'll really appreciate any help.
I have a DB where inventory items are stored, I'm displaying invontory records and built a display by brand filter everything is working fine till now.!
I'm trying to calculate the total sum of the instock field of the items table in the while loop. I couldn't figure how.
Thankx for your time.
here is the code I'm using:
<?
if (isset($f_filterbrand))
{
$cond = array();
if ($f_filterbrand != '*')
$cond[] = "(brands.id = $f_filterbrand)";
if (count($cond))
$cond = '(' . join(' AND ', $cond) . ') AND ';
else
$cond = '';
}
else
$cond = '';
$query_data = "SELECT
items.Id AS itemsid,
items.ref AS itemsref,
items.itemname AS itemsname,
items.instock AS instock,
items.brandid AS itemsbrandid,
brands.Id AS brandsid,
brands.brandname AS brandsname
FROM
items, brands
WHERE
$cond
items.brandid = brands.Id
";
$result = show_mysql_query("$query_data");
if (mysql_num_rows($result)){
// fetching result
while ($r = mysql_fetch_array($result)) {
// processing result cells
$me = $lines[] = sprintf("[
'<a href=javascript:edit(%s) title=\'Click to Edit %s Item info.\' >%s</a>',
'%s',
'%s',
'%s'
]",
$r['itemsid'],
$r['itemsref'],
$r['itemsref'],
$r['itemsname'],
$r['instock'],
$r['brandsname']
);
}
}
if (!mysql_num_rows($result)){
$me = $lines[] = "['-','-','0','-']";
$zimsg="Sorry... Nothing is found !! Try Another search.";
}
// joining lines up and printing the result
if (is_array($lines)) echo join(",\n", $lines);
?>