Jump to content

loop a php function


funbinod
 Share

Recommended Posts

how can i loop a result from a php function to loop through each 'id'?

 

like for all 'sid's, i want to use following function to get data...

/* above this i calculate value for each $cqty */$cqty = $oqty + $inqty - $outqty;$camt = "select date, pqty, prate, pamt from stock stjoin purchase p on st.sid = p.sid where st.sid = $sidunion allselect date, -sqty, srate, samt from stock stjoin sales s on st.sid = s.sid where st.sid = $sidunion allselect null, oqty, oprice, oamt from stock where sid = $sidorder by date asc";$dataSet = array();$camtresult = mysqli_query($connect, $camt);while ($row = mysqli_fetch_array($camtresult)){	$dataSet[] = $row;}function camt($dataSet, $cqty){    $totalPurchaseValue = 0;    $totalPurchaseQty = 0;    $done = false;    foreach($dataSet as $row)    {        // skip sales rows        if ($row['pqty'] < 0)        {            continue;        }        for ($i=0; $i<$row['pqty']; $i++ )        {            $totalPurchaseQty++;            $totalPurchaseValue += $row['prate'];            if ($totalPurchaseQty == $cqty)            {                return $totalPurchaseValue;            }        }    }    return $totalPurchaseValue;}// Determine the $countOfGoodsForSale$crate = camt($dataSet, $cqty) / $cqty;$camt = $cqty*$crate;

i tried while loop but it said---

Fatal error: Cannot redeclare camt() (previously declared in E:xampphtdocsacstock.php:73) in E:xampphtdocsacstock.php on line 73

please guide through

Edited by funbinod
Link to comment
Share on other sites

this function is only for 'sid=1'. i mean for single 'sid'. and is working properly.

but i asked for help to derive values for all 'sid's. i mean to ask u 'how to use this function more than once'.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...