Jump to content

I need a grand total of "$Total = odbc_result($result, "total");"


kat35601

Recommended Posts

Hello I am very new to php and programming and I need a grand  total of "$Total = odbc_result($result, "total");" but not sure of how to create it.

 

 

 



$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
echo "<table><tr>";
echo "<th>Entered</th>";
echo "<th>Orders</th>";
echo "<th>Total</th>";


while (odbc_fetch_row($result)) {
$EnteredBy= odbc_result($result,"ompCreatedBy");
$Orders= odbc_result($result, "orders");
$Total = odbc_result($result, "total");
//Grand total of total needed          


  echo "<tr><td>$EnteredBy</td>";
  echo "<td>$Orders</td>";
  echo "<td>$Total</td>";
  echo "<td>$Grand_Total</td>";
 }


odbc_close($connect);
?>
</body>
</html>

Edited by Ch0cu3r
Link to comment
Share on other sites

 

1>



$sql="select SO.ompCreatedBy, count(SO.ompSalesOrderID) as orders,round(sum(SO.ompOrderTotalBase),2) as total 
FROM   m1_DC.dbo.SalesOrders SO
Where    SO.ompOrderDate=CONVERT(varchar,GETDATE(),101)
Group by SO.ompCreatedBy";


 

 

2> first way I got it to work

Edited by Ch0cu3r
Link to comment
Share on other sites

From your posted query the part that says " round(sum(SO.ompOrderTotalBase),2) as total " gives you a total of that column for each of the ompcreatedby values.  How are you processing the output of your query?  In a loop?

 

Don't understand your next comment.

Link to comment
Share on other sites

<?php


$connect =odbc_connect("removed");
if(!$connect) {
exit("Connection Failed: " . $connect);
}


$sql="select SO.ompCreatedBy, count(SO.ompSalesOrderID) as orders,round(sum(SO.ompOrderTotalBase),2) as total 
FROM   m1_DC.dbo.SalesOrders SO
Where    SO.ompOrderDate=CONVERT(varchar,GETDATE(),101)
Group by SO.ompCreatedBy


" ;
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
echo "<table><tr>";
echo "<th>Entered</th>";
echo "<th>Orders</th>";
echo "<th>Total</th>";


while (odbc_fetch_row($result)) {
$EnteredBy= odbc_result($result,"ompCreatedBy");
$Orders= odbc_result($result, "orders");
$Total = odbc_result($result, "total");




  echo "<tr><td>$EnteredBy</td>";
  echo "<td>$Orders</td>";
  echo "<td>$Total</td>";


 }


odbc_close($connect);
?>

 

 

 

you 2 - you really should grab your results row by row instead of individually by column.  It's a waste of resources the way you are doing it.

me 2> first way I got it to work 

Edited by Ch0cu3r
Link to comment
Share on other sites

Not familiar with the odbc extension but I would guess you get each column in that loop this way:

 

 while ($row = odbc_fetch_array($result))
{

   echo "<tr><td>" . $row['ompCreatedBy'] ."</td>";
    echo "<td>" .$row['orders'] ."</td>";

    echo "<td>" . $row['total'] ."</td></tr>";
    $gr_total = $gr_total + $row['total'];
}

Link to comment
Share on other sites

Notice: Undefined variable: gr_total in /var/www/html/kk_orders_entered_by.php on line 37

Entered Orders Total EWOODY 16 3415.17 JDODSON 3 1509.01 REVANS 3 0.00 TMOTES 9 2760.57

 

$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
echo "<table><tr>";
echo "<th>Entered</th>";
echo "<th>Orders</th>";
echo "<th>Total</th>";
//****************************************************************
 while ($row = odbc_fetch_array($result))
{


  echo "<tr><td>" . $row['ompCreatedBy'] ."</td>";
  echo "<td>" .$row['orders'] ."</td>";
  echo "<td>" . $row['total'] ."</td></tr>";
    $gr_total = $gr_total + $row['total'];
}
//******************************************************************
Edited by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.