Jump to content

Recommended Posts

 the include returns a number 23,573.07 

 

so I would like it to show

 

" 23,573.07 | Week"

 

but what I get is

 

"23,753.07

| Week"

<div class="cont">
					<?php include 'bs_kf_production_price_week.php';echo "<p>| Week</p> "?>
					<br>
					<p><bold>$377</bold> | Pending</p>
					<br>
					<p><bold>$156</bold> | <bad>Denied</bad></p>
					<br>
					<p><img src="assets/img/up-small.png" alt=""> 12% Compared Last Month</p>

				</div>

Perhaps using a more universal coding method would work better. Instead of relying on some blind code to output a value for you, why not return the value in a var and then use the calling script to output it as it sees fit?


<html>
<head>
<title>Production</title>
</head>
<body>

<div class="wrapper">
<?php
$grandTotal = 0;
$connect =odbc_connect("removed");
if(!$connect) {
exit("Connection Failed: " . $connect);
}

$sql=" SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, tdate)) AS DATE
,ISNULL(trans, 'NON') AS trans
,ISNULL(Transactions.item, Snumbers.item) AS item
,count(serial) AS qty
,tuser
,sum(M1_KF.dbo.PartUnitSalePrices.imhUnitSalePrice) as TotalPrice
FROM Orbedata.dbo.SNumbers
LEFT OUTER JOIN OrbeData.dbo.Transactions ON snum = serial
INNER JOIN M1_KF.dbo.PartUnitSalePrices ON Orbedata.dbo.transactions.item = M1_KF.dbo.PartUnitSalePrices.imhPartID
WHERE tdate>=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) and tdate<=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
AND trans = 'fpr'
GROUP BY DATEADD(dd, 0, DATEDIFF(dd, 0, tdate))
,ISNULL(trans, 'NON')
,ISNULL(Transactions.item, Snumbers.item)
,tuser
,Orbedata.dbo.transactions.qty
order by tuser,item


";

$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}


while (odbc_fetch_row($result)) {

$scanner=odbc_result($result,"tuser");
$Item=odbc_result($result,"item");
$Qty=odbc_result($result,"qty");
$Price=odbc_result($result,"TotalPrice");

$num = number_format($Price, 2);
$grandTotal += $Price;
$num2 = number_format( $grandTotal, 2);

}
odbc_close($connect);
echo "$num2";
?>
</div>
</body>
</html>

You wrap your simple db query and logic in some html code and then return a result to the main file to be output? Very strange way of coding.

 

So instead of echo'ing that $num2 var, just USE the var where you need it. Like in the other echo that you are executing.

Is there a reason for including all the HTML tags? It seems like the include file could be cut down to something like this:

<?php
$grandTotal = 0;
$connect =odbc_connect("removed");
if(!$connect) {
exit("Connection Failed: " . $connect);
}
 
$sql=" SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, tdate)) AS DATE
,ISNULL(trans, 'NON') AS trans
,ISNULL(Transactions.item, Snumbers.item) AS item
,count(serial) AS qty
,tuser
,sum(M1_KF.dbo.PartUnitSalePrices.imhUnitSalePrice) as TotalPrice
FROM Orbedata.dbo.SNumbers
   LEFT OUTER JOIN OrbeData.dbo.Transactions ON snum = serial 
INNER JOIN M1_KF.dbo.PartUnitSalePrices ON Orbedata.dbo.transactions.item = M1_KF.dbo.PartUnitSalePrices.imhPartID
WHERE  tdate>=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) and   tdate<=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
AND trans = 'fpr'
GROUP BY DATEADD(dd, 0, DATEDIFF(dd, 0, tdate))
,ISNULL(trans, 'NON')
,ISNULL(Transactions.item, Snumbers.item)
,tuser
,Orbedata.dbo.transactions.qty
order by tuser,item
 
 
 ";
 
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
 
 
while (odbc_fetch_row($result)) {
 
  $scanner=odbc_result($result,"tuser");
  $Item=odbc_result($result,"item");
  $Qty=odbc_result($result,"qty");
   $Price=odbc_result($result,"TotalPrice");
 
$num = number_format($Price, 2);
 $grandTotal += $Price;
 $num2 = number_format( $grandTotal, 2);
 
}
odbc_close($connect);
echo "$num2";
?>

Or better yet, you could create your own function using the above code and then returning the value of $num2. More information about creating functions can be found here:

http://php.net/manual/en/functions.user-defined.php

Let me give a little more information. I have about 75  pages like this that I want to pull one or two numbers off of to put on one page. All have different SQL Databases and Tables that they pull from.

 

Is the code for all / most of the pages very similar...maybe a different database name here and a table name there? If so, you could look into creating a function using the code used by all / most of the scripts. And then pass any specific information, like a table name, as function arguments.

Pages? What pages? Scripts that do the same thing over and over? And they all contain a bunch of useless html that you just want to glean some data from? Doesn't sound like the original purpose of all this effort.

 

Personally I would do what cyberRobot said - dump the html, keep the php/sql logic and wrap each in a function. Open one db connection and then call each function and assemble the individual outputs at the end (or wherever) and output them.

Have you tried removing the extra HTML? For "bs_kf_production_price_week.php", instead of

<html>
<head>
<title>Production</title>
</head>
<body>
 
<div class="wrapper">
<?php
$grandTotal = 0;
$connect =odbc_connect("removed");
if(!$connect) {
exit("Connection Failed: " . $connect);
}
 
$sql=" SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, tdate)) AS DATE
,ISNULL(trans, 'NON') AS trans
,ISNULL(Transactions.item, Snumbers.item) AS item
,count(serial) AS qty
,tuser
,sum(M1_KF.dbo.PartUnitSalePrices.imhUnitSalePrice) as TotalPrice
FROM Orbedata.dbo.SNumbers
   LEFT OUTER JOIN OrbeData.dbo.Transactions ON snum = serial 
INNER JOIN M1_KF.dbo.PartUnitSalePrices ON Orbedata.dbo.transactions.item = M1_KF.dbo.PartUnitSalePrices.imhPartID
WHERE  tdate>=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) and   tdate<=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
AND trans = 'fpr'
GROUP BY DATEADD(dd, 0, DATEDIFF(dd, 0, tdate))
,ISNULL(trans, 'NON')
,ISNULL(Transactions.item, Snumbers.item)
,tuser
,Orbedata.dbo.transactions.qty
order by tuser,item
 
 
 ";
 
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
 
 
while (odbc_fetch_row($result)) {
 
  $scanner=odbc_result($result,"tuser");
  $Item=odbc_result($result,"item");
  $Qty=odbc_result($result,"qty");
   $Price=odbc_result($result,"TotalPrice");
 
$num = number_format($Price, 2);
 $grandTotal += $Price;
 $num2 = number_format( $grandTotal, 2);
 
}
odbc_close($connect);
echo "$num2";
?>
</div>
</body>
</html>
 
Try
<?php
$grandTotal = 0;
$connect =odbc_connect("removed");
if(!$connect) {
exit("Connection Failed: " . $connect);
}
 
$sql=" SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, tdate)) AS DATE
,ISNULL(trans, 'NON') AS trans
,ISNULL(Transactions.item, Snumbers.item) AS item
,count(serial) AS qty
,tuser
,sum(M1_KF.dbo.PartUnitSalePrices.imhUnitSalePrice) as TotalPrice
FROM Orbedata.dbo.SNumbers
   LEFT OUTER JOIN OrbeData.dbo.Transactions ON snum = serial 
INNER JOIN M1_KF.dbo.PartUnitSalePrices ON Orbedata.dbo.transactions.item = M1_KF.dbo.PartUnitSalePrices.imhPartID
WHERE  tdate>=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) and   tdate<=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),6)
AND trans = 'fpr'
GROUP BY DATEADD(dd, 0, DATEDIFF(dd, 0, tdate))
,ISNULL(trans, 'NON')
,ISNULL(Transactions.item, Snumbers.item)
,tuser
,Orbedata.dbo.transactions.qty
order by tuser,item
 
 
 ";
 
$result =odbc_exec($connect,$sql);
if(!$result){
exit("Error in SQL");
}
 
 
while (odbc_fetch_row($result)) {
 
  $scanner=odbc_result($result,"tuser");
  $Item=odbc_result($result,"item");
  $Qty=odbc_result($result,"qty");
   $Price=odbc_result($result,"TotalPrice");
 
$num = number_format($Price, 2);
 $grandTotal += $Price;
 $num2 = number_format( $grandTotal, 2);
 
}
odbc_close($connect);
echo "$num2";
?>

As was suggested by CyberRobot - you should work on formatting it so that you can use one set of code for all of your needs to make the whole process simpler and easier to maintain. All that you want from the included file is some data. No need for html it sounds like, altho I don't know how your whole process handles that now.

 

In the end you could have a script that looks like this:

 

(open db connection)

(set some parameters to do a query such as table name, values that alter the query results)

(call a function to do the query and return the result value)

(do something with the results, such as outputting them)

(do this all over again with new parameters).

and repeat.

 

You'll probably only have one include for the connection logic and another for the sql code.

All 75 +pages are standalone pages meaning that user all day open these pages to get information. I wanted to create a page that would show all the total information for each page so you could just look at one page see whats going on and then if you needed the detail you could click the link to take you to that detail  page. I robbed code from each page to create my pages for the totals not removing all that html but a lot.I now envision what I  should do is create the pages as functions. I am not sure on the database connection because these reports cover from Labor, Sales, Production, Shipping. Three different database on two different servers. I thing maybe three pages one for labor, one for sales and one for everything else and then just include all three on the main page. 

It sounds like a good plan. Could be done in one script, or in multiple. Perhaps create 3 connection functions and use them before the groups of queries that access them. The key would be developing that query function (or functions) that can be used over and over again for each of your so-called 'pages'.

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.