How to display the total size in MB
<p>Just wondering if someone can help me out with this quickly.</p>

<p>I have a php script It works fine, However, I would like it to display the <code>Total Memory</code> in MB not in kb.</p>

<pre><code>&lt;div class="TitleBar"&gt;VM List&lt;/div&gt;   

&lt;?php
    $conn = pg_connect("host=".MGRCONFIG_DB_HOST."  port=".MGRCONFIG_DB_PORT." dbname=".MGRCONFIG_DB_NAME. " user=" .MGRCONFIG_DB_USER." password=".MGRCONFIG_DB_PASSWORD);
    if (!$conn) 
    {
        AddLog("vmlist.php","Could not connect to Database",ERR_DEBUG_HIGH);        
    }
    $query = "select guid,vmname,hostid,guestosname,cputype,cpucycle,totalmemory from vmobjects order by vmname";
    $result = pg_query($conn,$query);
    AddLog("vmlist.php","Query: ".$query,ERR_DEBUG_HIGH);
    $guid_array=Array();
    $lastname_array=Array();
    $firstname_array=Array();
    $osname_array=Array();
    $cptype_array=Array();
    $cpcycle_array=Array();
    $tom_array=Array();
    $no_of_record = 0;              

    while ($row = pg_fetch_array($result)) 
    {   
        $num_rows=0;
        $subquery = "select bussinessappid from bussinessapppolicyassoc where vmid ='".$row[0]."'";
        AddLog("vmlist.php","Query: ".$query,ERR_DEBUG_LOW);
        $subresult = pg_query($conn,$subquery);
        $num_rows=pg_num_rows($subresult);

        $guid_array[$no_of_record] = $row[0].'|'.$num_rows;
        $lastname_array[$no_of_record] = $row[1];

        $hostid = $row[2];
        $osname_array[$no_of_record] = $row[3];
        $cptype_array[$no_of_record] = $row[4];
        $cpcycle_array[$no_of_record] = $row[5];
        $tom_array[$no_of_record] = $row[6];                    

        $query = "select name from hosts where guid='".$hostid."'";
        $result1 = pg_query($conn,$query);
        AddLog("vmlist.php","Query: ".$query,ERR_DEBUG_HIGH);
        while ($row1 = pg_fetch_array($result1)) 
        {
             $firstname_array[$no_of_record] = $row1[0];
        }                       
        $no_of_record++;                    
    }

    pg_close($conn);
?&gt;
      &lt;table class="objList" cellspacing="0" cellpadding="0" id="vmtable"&gt;
        &lt;tr&gt;
          &lt;td class="tbHeader"&gt;&lt;/td&gt;
          &lt;!--&lt;td class="tbHeader"&gt;&lt;/td&gt;
          &lt;td class="tbHeader"&gt;&lt;/td&gt;--&gt;
          &lt;td class="tbHeader"&gt;Name &lt;/td&gt;
          &lt;td class="tbHeader"&gt;Hostname&lt;/td&gt;
          &lt;td class="tbHeader"&gt;OS Name&lt;/td&gt;
          &lt;td class="tbHeader"&gt;CPU Type&lt;/td&gt;
          &lt;td class="tbHeader"&gt;CPU Cycle&lt;/td&gt;
          &lt;td class="tbHeader"&gt;Total Memory&lt;/td&gt;




        &lt;/tr&gt;
        &lt;?php

            for ($i =0; $i &lt; $no_of_record; $i++)
            {
                echo "&lt;tr class=\"objList\" id=\"".$i."\"&gt;";

                echo "&lt;td height=\"20\" width=\"25\" valign=\"top\" class=\"objList\"&gt;";

                //if(strcmp($_SESSION['mntvm_edit'],"1") == 0 || strcmp($_SESSION['mntvm_delete'],"1") == 0)
                {
                    echo "&lt;img id=\"".$guid_array[$i]."\" src=\"images/icon-reports.gif\" alt=\"Options\" title=\"Options\" width=\"25\" height=\"20\" border=\"0\"&gt;";
                }
                echo "&lt;/td&gt;";
                echo "&lt;td class=\"objList\" value=\"".$lastname_array[$i]."\" width=\"\"&gt;".$lastname_array[$i]."&lt;/td&gt;";             

                echo "&lt;td class=\"objList\" value=\"".$firstname_array[$i]."\" width=\"\"&gt;".$firstname_array[$i]."&lt;/td&gt;";   

                echo "&lt;td class=\"objList\" value=\"".$osname_array[$i]."\" width=\"\"&gt;".$osname_array[$i]."&lt;/td&gt;";
                echo "&lt;td class=\"objList\" value=\"".$cptype_array[$i]."\" width=\"\"&gt;".$cptype_array[$i]."&lt;/td&gt;";
                echo "&lt;td class=\"objList\" value=\"".$cpcycle_array[$i]."\" width=\"\"&gt;".$cpcycle_array[$i]."&lt;/td&gt;";
                echo "&lt;td class=\"objList\" value=\"".$tom_array[$i]."\" width=\"\"&gt;".$tom_array[$i]."&lt;/td&gt;";

                echo "&lt;/tr&gt;";                   
            }
            ?&gt;
      &lt;/table&gt;  
&lt;/div&gt;
</code></pre>
