Jump to content

loop a php function


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...