kat35601 Posted August 8, 2016 Share Posted August 8, 2016 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> Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/ Share on other sites More sharing options...
benanamen Posted August 8, 2016 Share Posted August 8, 2016 (edited) LOL! Move the opening <p> before the include. And no need to echo | week. That is less than basic Html. Edited August 8, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535773 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 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? Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535775 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 I tried it like this but I get the same results <p><?php include 'bs_kf_production_price_week.php';?>| Weeks</p> Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535776 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 Then you really need to follow my suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535777 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 I am not sure how to dump the contents into a var something like this: <?php ob_start(); include 'bs_kf_production_price_week.php'; $weekprod= ob_get_contents(); echo "<p> $weekprod;| Weeks</p> "; ob_end_clean(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535778 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 Modify the include file to store a var instead of echo'ing it. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535779 Share on other sites More sharing options...
cyberRobot Posted August 8, 2016 Share Posted August 8, 2016 What does the code for "bs_kf_production_price_week.php" look like? Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535780 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 <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> Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535781 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535782 Share on other sites More sharing options...
cyberRobot Posted August 8, 2016 Share Posted August 8, 2016 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 Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535783 Share on other sites More sharing options...
cyberRobot Posted August 8, 2016 Share Posted August 8, 2016 Side note: have you considered putting the database connection code into a separate include file? That way you could import the code as need. And you would only need to update the database password, for example, in one location. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535784 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535785 Share on other sites More sharing options...
cyberRobot Posted August 8, 2016 Share Posted August 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535786 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535787 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 Yes we are a little off track from my original question. How do I get <?php include 'bs_kf_production_price_week.php';echo "<p>| Week</p> "?> or <p><?php include 'bs_kf_production_price_week.php';| Week</p> "?> to print on one line? Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535788 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 echo "$num2 | Week"; And remove the echo $num2 from the include-file. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535789 Share on other sites More sharing options...
cyberRobot Posted August 8, 2016 Share Posted August 8, 2016 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535790 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 No I have not tried with all the html removed I will try that now. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535791 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535792 Share on other sites More sharing options...
kat35601 Posted August 8, 2016 Author Share Posted August 8, 2016 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. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535793 Share on other sites More sharing options...
ginerjm Posted August 8, 2016 Share Posted August 8, 2016 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'. Quote Link to comment https://forums.phpfreaks.com/topic/301790-format-so-that-php-and-html-on-same-line/#findComment-1535795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.