I've used both extensively.
NodeJS and PHP both run server side.

Relative Features of Node:
  • Typically run standalone without apache or nginx
  • Is not multi threaded, but is defaulted as async (which makes it non-blocking)
  • It's javascript syntax (the more complex the feature, the less built out it is)
  • A lot of devs get super excited, build a library, then don't keep up with the next flavor of node
  • npm is cool, until its not. It supports windows, but will break pathing after a while.
  • hasn't been used a lot in ecommerce server side environments
  • Make sure your Database has a module.
  • Make sure you figure out how you are going to keep it running (as a service / cronjob?)
Relative Features of PHP
  • Typically run behind apache or nginx (standalone is considered beta, not for production)
  • Is not multithreaded and a single process is blocking (apache/nginex spawn multiple processes). Additional ReactPHP.
  • Php syntax - just happens to be very clean.
  • Composer is cool.
  • much more mature in the e-commerce space.
  • Your database is probably supported

I personally prefer PHP - it's more mature and I like the syntax.

You are correct in your suspicion, you do need an SMTP server. If you are running in a Windows environment, the 'mail' function might use a built in Windows SMTP (which might need to be configured).

Here is the PHP documentation.
More specifically, the runtime configuration

Also, are you getting any specific error message? If not, what is your output? Do you have any PHP Ini settings for mail?

To Ips's point, I would recommend asort.
It also helps to reduce the 'scope' of the issue. You have a double array, but only the sort on the outer array is relevant. I've removed everything else. Now, you may not need asort if you don't care about the index. The 'printout' from the following method should clarify.

  public function ExplanationIndex()
    {
        $data = [ // initialize everything
            'title' => 'User Group Permissions'            
        ]; 

        // sample 'file' list, unsorted.
        $file_list = ['z','y','x','w','a','b','c','d','e'];
        echo 'before';
        print_r($file_list);

        // initialize the array
        $controller_file_list = [];
        foreach ($file_list as $file)
        {
            $controller_file_list[] = [
                'name' =>           $file.'name',
                'controller' =>     $file.'controller',
                'module' =>         [rand(0,100),rand(0,100),rand(0,100),rand(0,100),rand(0,100)],
                'install' =>        $file,
                'installed' =>      (bool)rand(0,1)
            ];
        }

        asort($controller_file_list);        
        echo 'after';
        print_r($controller_file_list);
        $data['controller_files'] = $controller_file_list;
    }

Nightrain is an interesting Python wrapper of a PHP webserver running on localhost. It still uses up a port. Essentially, someone made a browser for PHP and burried all the browser elements to make it look like an application.

Yes, it does allow you to make a 'application' looking thing. However - in its current state you cannot even hide the console window in the background.

Currently, php can run standalone as a 'desktop application' - but it does not have a decent method for visual rendering (i.e. it runs command line). The optimum approach to convert to a Desktop application would involve php without a webserver running.

Anyhow, it is a good effort, it 'looks' like what you might want for an application - but it definately does not behave like one.

RikTelner commented: Thank you for your contribution. +2
diafol commented: havent tried it yet - good observation - thanks +15
Huge Disclaimer about security

The first, and most critical piece of information is that your query is vulnerable to an injection attack. In fact, your current problem is the equivalent to how an injection attack works.

Here's a not quite appreviated rundown of how PHP interacts with SQL. First, to run a query on SQL, you need a string in PHP select somevar from some table where table.col='value';. This works great. So we move to the next step of making the query dynamic and adding a variable. select somevar from sometable where table.col=$value;. This still seems fine, but in fact could be susceptible to an attack. For you see, the $value could really be ANY value. Let's say for example, $value = '2;drop sometable;'. Now, you run the full query as this: select somevar from sometable where table.col=2;drop sometable;. In your question, you are getting the value from a $_POST variable, meaning, anyone who can view the page can do anything to the database.

Security Suggestion

This would involve using something like the PDO driver, or the MYSQLi driver.

Examples for MySQLI
Examples for PDO

Converting to a Prepared Query will help to secure your application.

Specific variable issue

Now, finally, down to the exact issue:

  1. What is $y?
  2. What are you passing into $_POST['goodsDesc']?
$stockData = QueryForStock($connect);
echo BuildStockDataHtml($stockData, $connect);

/**
 * 
 * @param link $connect
 * @return array
 */
function QueryForStock($connect)
{
    $results = array();
    $query  = "SELECT sid, oqty, icode, item, iunit, icat FROM stock";

    try
    {
        $result = mysqli_query($connect, $query);

        while ($row = mysqli_fetch_array($result)) 
        {
            $results[] = $row;
        }

        mysqli_free_result($result);
    }
    catch(Exception $e)
    {
        error_log($e . __FILE__.' '.__LINE__);
        $results = array();
    }
    return $results;
}

function QueryForItemInward($sid, $connect)
{
    $results = array();

    $statement = mysqli_prepare($connect, "SELECT sum(qty) FROM purchase WHERE sid=?");
    mysqli_stmt_bind_param($statement,'i', $sid);
    mysqli_stmt_execute($statement);
    $statement->bind_result($total);
    $statement->fetch();
    $statement->close();

    return (int)$total;
}

function QueryForItemOutward($sid, $connect)
{
    $results = array();

    $statement = mysqli_prepare($connect, "SELECT sum(qty) FROM sales WHERE sid=?");
    mysqli_stmt_bind_param($statement,'i', $sid);
    mysqli_stmt_execute($statement);
    $statement->bind_result($total);
    $statement->fetch();
    $statement->close();

    return (int)$total;
}

function QueryDataForCurrentValue($sid, $connect)
{
    $query = <<<QUERY
select date, qty, rate, amt from stock st
join purchase p on st.sid = p.sid where st.sid = ?
union all
select date, -qty, rate, amt from stock st
join sales s on st.sid = s.sid where st.sid = ?
union all
select null, oqty, oprice, oamt from stock where sid = ?
order by date desc;
QUERY;

    $statement = mysqli_prepare($connect, $query);
    mysqli_stmt_bind_param($statement,'iii', $sid, $sid, $sid);
    mysqli_stmt_execute($statement);
    $statement->bind_result( $date, $qty, $rate, $amt);

    while($statement->fetch())
    {
        $results[] = [ 'date' => $date, 'qty'=> $qty, 'rate' => $rate, 'amt' => $amt];
    }

    $statement->close();

    return $results;
}

function BuildStockDataHtml(array $stockData, $connect)
{

    $tableRows = '';
    foreach($stockData as $stock)
    {
        $inQuantity         = QueryForItemInward($stock['sid'], $connect);
        $outQuantity        = QueryForItemOutward($stock['sid'], $connect);
        $currentQuantity    = $stock['oqty'] + $inQuantity - $outQuantity;
        $costOfGoodsForSale = CostOfGoodsForSale($stock['sid'], $connect, $currentQuantity);

         $averageCostOfGoodsForSale = $costOfGoodsForSale / ...

This can all likely be optimized. I wrote the CostOfGoodsForSale for a single SID.

You'll need to calculate the $countofgoodsforsale - good practice with PHP.
Then for the data table, it is the results from the query built into an array.

$sid = 1;
$query = <<<QUERY
select date, qty, rate, amt from stock st
join purchase p on st.sid = p.sid where st.sid = {$sid}
union all
select date, -qty, rate, amt from stock st
join sales s on st.sid = s.sid where st.sid = {$sid}
union all
select null, oqty, oprice, oamt from stock where sid = {$sid}
order by date desc;
QUERY;

$dataSet = array();
$result = mysql_query($query, $connection);
while(($row = mysql_fetch_array($result, 1) )!== false)
{
    $dataSet[] = $row;
}

// Determine the $countOfGoodsForSale

$finalResult = CostOfGoodsForSale($dataSet, $countOfGoodsForSale) / $countOfGoodsForSale;

If this answers your question, could you be so kind as to mark the question as resolved?

Background

The direct relationship between php and javascript is primarily one way. PHP on the server can be built out to print out javascript. However, javascript is a client side language. Once the code reaches the client, the only way to get back to the PHP is to return to the server (via Ajax or a new Webpage request).

This means you could build up your javascript array and send it back to the server to be handled by your array. But you cannot directly set a php value from javascript.

Solution Ideas
  1. You might try using jQuery as you are already using a framework.
  2. Another approach (with the basic concept) is a php formhttp://www.w3schools.com/php/php_forms.asp
  3. It is possible to do it without jquery, but if you aren't familiar with setting up ajax, cross browser support is already baked into jQuery.