Jump to content

ShadowMage

Members
  • Posts

    3,476
  • Joined

  • Last visited

Everything posted by ShadowMage

  1. I have two tables: OrderHed and OrderRel. There are multiple records in OrderRel for each OrderHed. I'm trying to pull out the first record from OrderRel for each OrderHed. I have the following query, but it gives me a "Function sequence error" SELECT OrderHed.OrderNum, OrderRel.Plant FROM OrderHed INNER JOIN (SELECT Plant FROM OrderRel WHERE OrderRel.OrderNum = OrderHed.OrderNum LIMIT 1) OrdRel WHERE ((OrderHed.OpenOrder <> 0) AND (OrderHed.VoidOrder = 0)) ORDER BY OrderHed.OrderNum DESC Can anyone help me, please?
  2. That's unfortunate. And also probably true... I much prefer forums for this type of thing and I actually kind of despise the social media type stuff. I have a strange urge to make a comment about whipper-snappers and ... lawns ... and? 🤔
  3. Shoot. Forgot I posted here. It ended up being an issue with Epicor (the DB I'm connecting to). Turns out that UserComp.PlantList is a varchar(1000) field and any time we try to pull out a 1000 character field from Epicor in PHP, we have to use CAST(fieldname AS varchar(1000)) or we get funky, completely unrelated, inaccurate error messages. Like this one. Anyway, thanks for looking, Ingolme. Much appreciated. On a completely unrelated sidenote: What happened to this place? This used to be a fairly active community, but now it's almost like a ghost town...😕
  4. I have the following query: $sql = "SELECT UserFile.DcdUserID, UserComp.PlantList FROM UserFile INNER JOIN UserComp ON UserFile.DcdUserID = UserComp.DcdUserID"; but it's giving me the following error: PHP Warning: odbc_fetch_array(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Ambiguous column name 'DcdUserID'., SQL state 37000 in SQLGetData If I adjust the query with an alias on 'DcdUserID' as follows: $sql = "SELECT UserFile.DcdUserID AS 'UserID', UserComp.PlantList FROM UserFile INNER JOIN UserComp ON UserFile.DcdUserID = UserComp.DcdUserID"; then it tells me that 'UserID' is an invalid column name. Any ideas what's going on here? I can't see any issues with the SQL and in fact both queries run in a standalone querying tool we use (ODBC Test Utility) without issue.
  5. That seems to have done the trick on getting the PHPSpreadsheet stuff to load. But it looks like I've got some prerequisite stuff to take care of now as it's giving me an error saying it can't load psr/simple-cache which is not part of the PHPSpreadsheet library. Thanks for all the help, Ingolme!! I'll be back if I run into more snags. 😄
  6. So I've got this code: require('PhpSpreadsheet\autoload.php'); use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'Hello World !'); $writer = new Xlsx($spreadsheet); $writer->save('hello world.xlsx'); Which was copied directly from their documentation as a test. However, I get this error: PHP Warning: include(PhpSpreadsheet/src/PhpOffice\PhpSpreadsheet\Spreadsheet.php): failed to open stream: No such file or directory The autoload.php file looks like this: spl_autoload_register(function ($class_name) { // include 'PhpSpreadsheet/src/PHPSpreadsheet/'.$class_name.'.php'; include 'PhpSpreadsheet/src/'.$class_name.'.php'; }); I copied the files from their original folder (PHPSpreadsheet) up a level into the src folder just to eliminate the extra file path length. However, I did try it with the original file structure when it failed. Both ways produce the same error. It looks to me like maybe the use lines aren't functioning correctly? Maybe? It looks like the autoload function is pulling in the full namespace of the class instead of just the class name. Any ideas what's going on?
  7. So do I need to change the $class_name variable? Or just make sure the "src/PHPSpreadsheet" part is pointing to the right place? EDIT: Nvmind, answered my own question with a bit of research. 😁 Found a StackOverflow article that explains autoloading. Just need to change the "src/PHPSpreadsheet" part. Let's see if I can get this thing working now... I might be back... Thanks, Ingolme!!
  8. ShadowMage

    Write to Excel

    My company has started asking for more and more Excel-based data. We used to just print the data to a table and then copy/paste from the browser to Excel, but they're wanting auto emailers and stuff like that now. I did a little research and it seems like PHPSpreadsheet is the way to go. It seems to be the most up to date, and still actively supported. Problem is, I'm not sure how to set it up and use it. Their documentation (https://phpspreadsheet.readthedocs.io/en/latest/) is a little vague on that part. It reads like this is supposed to be installed into a project (similar to Visual Studio's projects) but I didn't even know that was a thing with PHP. I've only ever used PHP in a webserver environment (maybe that's the project?). I've never used Composer so I have no clue where to even start. So, I guess my question is, can somebody offer some assistance in setting this up and/or using it in a webserver environment? Or, offer some alternatives to PHPSpreadsheet that are easier to use? Thanks in advance.
  9. Bumping this again because it is really a pain to try and work around this issue. Does anyone have any ideas as to how I can get all the output back? It's incredibly helpful in trying to track down undefined indexes and such within loops.
  10. ah, ok. I'll give it a shot with iframes then. Thanks guys.
  11. Totally forgot I posted this until I was asked about it again this morning... I thought iframes were deprecated or not recommended?
  12. This is strange but recently my page stopped displaying PDFs using the object tag. Nothing has changed on the page (in fact, I haven't worked with it in a very long time and there's no one else besides my supervisor who can edit it; I'm 99.99999% sure he hasn't touched it either). I guess what I want to ask is if there's anything that looks out of place with my code: $x = 0; foreach ($arrPDF as $pdf) { echo "<object id='bulletin".$x."' data='../path/".$pdf."' type='application/pdf'>\n"; echo "<span class='error'>Error: Could not load PDF. Your browser does not support embedded objects.</span>\n"; echo "</object>\n"; $x++; } This code used to work, then just seemingly at random one day, it decided not to. Used to display the PDFs, now I just get the error message. Any suggestions? I've already tried updating the browser. I've tried it in FireFox, Chrome, and Edge. None of them display the PDFs. Everything I've seen online about the <object> tag suggests this code should be just fine. Is there a different/better way to embed a PDF that I'm not finding?
  13. The problem is not data coming from an HTML form. As mentioned, memos that are entered from the intranet (the HTML forms) are functioning correctly. The problem appears when users copy/paste directly into the ERP system. To try to further clarify, memos can be entered in one of two ways. Through a form on the intranet or directly into the ERP system. Those memos that come from the intranet form are functioning fine and do not have any character encoding issues. Entering memos directly doesn't cause issues UNLESS the user copy/pastes data (from an Outlook email, for example) into the memo. The intranet and the ERP system are two separate entities, not really connected in any way except for sharing data back and forth through an ODBC connection. The intranet is of our own design and we have full control over it. As mentioned, it connects to the ERP system's database through ODBC to retrieve data and occasionally very limited writing of data to Memos and certain other similar things. The ERP system (Epicor, in case you're wondering) is not our own and we have very, very limited control of the database it uses and none over how it interacts with said database.
  14. So, first a little background on the setup/system we're running. We have an ERP system where users enter memos and notes on quotes/orders. We also have an intranet that pulls this information back out to run reports and such. The problem I'm facing, is that users are copy/pasting data into the memo text which is creating a character encoding issue. The memo text is displaying in the web browser as the black diamond with a question mark for certain specific characters (like apostrophe's). Manually typed text doesn't seem to have this issue, nor does text that comes from the intranet and is inserted into the ERP system. It is only data that's copy/pasted directly into the ERP system. How do I detect these wrongly encoded strings and display them properly? I did try to just use utf8_encode() on the text, but that changes the black diamond to a white box. I also see there is a iconv() function to convert strings to specific encodings, but it requires an input encoding, and I have no idea what the starting charset is. I found the mb_detect_encoding() function, but that gives me a fatal error. I tried to enable the mbstring extension in php.ini but that didn't seem to make any difference.
  15. Ok, so this is stemming from the fact that I can't get any output from PHP except errors when they occur (as described here) but since that doesn't seem to be an issue that's going to be resolved any time soon, I need to figure out how to work around it. So, I split this issue (which I also posted in the linked thread) off into it's own separate thread to see if I can resolve this particular issue. Anyway, I'm getting this error: PHP Warning: A non-numeric value encountered in ...filepath... on line 166 Line 166 looks like this: $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; The error doesn't even tell me which of the three variables is throwing the error. Normally, this wouldn't be an issue, because I'd just print out all the variables in the equation to see what they're being set to. However, due to the previously mentioned issue, that's not possible. So, I've tried to catch this error in the following ways: try { $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; } catch (Throwable $e) { echo "<pre>".print_r($Dim, true)."</pre>"; } and: $blnDump = false; $which = ''; if (!is_numeric($Dim['bays'])) { $blnDump = true; $which = 'bays'; } elseif (!is_numeric($Dim['purlins'])) { $blnDump = true; $which = 'purlins'; } elseif (!is_numeric($Dim['qty'])) { $blnDump = true; $which = 'qty'; } if ($blnDump) echo "$which was non-numeric:<br /><pre>".print_r($Dim, true)."</pre>"; but neither one catches the error and I just get the error printed on the page. The error prints twice, because the code above is in a function that gets called multiple times within a loop, and the issue apparently is occurring on two different iterations of the loop. And, because the code is in a loop, I can't use exit; or die(); to kill the script and print my debugging messages, because it kills the script on the first iteration of the loop. As luck would have it, the first iteration is error free and is therefore unhelpful to say the least. Please help?
  16. This is really beginning to be a problem... I've found all the division by 0 errors I had before, but I still have this guy: PHP Warning: A non-numeric value encountered in ...filepath... on line 166 Line 166 looks like this: $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; The error doesn't even tell me which of the three variables is throwing the error. Normally, this wouldn't be an issue, because I'd just print out all the variables in the equation to see what they're being set to. However, because of the issue that started this thread, that's not possible. I've tried to catch this error in the following ways: try { $numPieces = ($Dim['bays']*$Dim['purlins'])*$Dim['qty']; } catch (Throwable $e) { echo "<pre>".print_r($Dim, true)."</pre>"; } and: $blnDump = false; $which = ''; if (!is_numeric($Dim['bays'])) { $blnDump = true; $which = 'bays'; } elseif (!is_numeric($Dim['purlins'])) { $blnDump = true; $which = 'purlins'; } elseif (!is_numeric($Dim['qty'])) { $blnDump = true; $which = 'qty'; } if ($blnDump) echo "$which was non-numeric:<br /><pre>".print_r($Dim, true)."</pre>"; but neither one catches the error and I just get the error printed on the page. The error prints twice, because the code above is in a function that gets called multiple times within a loop, and the issue apparently is occurring on two different iterations of the loop. And, because the code is in a loop, I can't use exit; or die(); to kill the script and print my debugging messages, because it kills the script on the first iteration of the loop. As luck would have it, the first iteration is error free and is therefore unhelpful to say the least.
  17. So, I'm bumping this back up because it's become an issue again. I had been working around it using die() to print out variables and such just before any offending lines, but I've encountered a situation now where that doesn't work. Consider the following: $x = 10; $y = 3; for ($z=0; $z<10; $z++) { echo "Attempt $x / $y: "; echo ($x/$y)."<br />"; $y--; } In PHP 5, I would get output as: Attempt 10 / 3: 3.33333333 Attempt 10 / 2: 5 Attempt 10 / 1: 10 Attempt 10 / 0: PHP Warning: Division by zero in C:\inetpub\major\test.php on line 37 Now, in PHP 7, I just get the error. And I can't use die() in the loop to print the "attempt..." line because the first iteration through the loop is correct and functional. I really need to figure out how to make PHP output everything again like it used to. While writing this, I thought of a workaround for the above situation. I could put a conditional to check the value of $y like this: $x = 10; $y = 3; for ($z=0; $z<10; $z++) { if ($y==0) echo "dividing by 0: $x / $y<br />"; echo "Attempt $x / $y: "; echo ($x/$y)."<br />"; $y--; } Or use a try/catch block for more complicated equations. Maybe this is best practice anyway? EDIT: Turns out a try/catch doesn't catch this error apparently... I don't know. Still seems silly to me that PHP would prevent all other output in the event of a non-fatal error.
  18. My code doesn't halt either. As mentioned, I can get multiple notices, but I get no other output besides the error notices. As an example: echo "Hello World"; echo $undefinedVar1; echo $undefinedVar2; The above code, in PHP 5, would print the "Hello World" line and then the undefined variable errors (both of them). In 7, I still get both error messages, but not the "Hello World" line. EDIT: Oh, and my error reporting level is the same in both: error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
  19. I've recently upgraded to PHP 7 from PHP 5, but I've noticed now that warnings and notices are preventing other output from being displayed. In PHP 5, if I tried to echo an undefined variable, I would get the notice in the midst of all the other output. But now, in PHP 7 it seems to just output the notice and nothing else, although I do get several notices if I have the undefined variable in a loop. This is an issue for me, because I often place echo statements around the code when I'm debugging to trace the flow of the code, but that doesn't work in PHP 7 anymore because none of my debugging statements are being printed to the screen. I can make it work and adjust my debugging procedure by placing exit calls just before the line that's generating the error, but I'm still curious if there's a INI setting or something that can change this behavior?
  20. Explicitly setting the length to 1000 seems to work as well. Looks like it's just the CAST that's doing the trick even though it's supposed to already be text. Also, good to know about the default. Although in my case that doesn't seem to apply. I've several values that are over 30 characters and they're not being truncated. Of course, that doesn't mean that the default isn't some other value that I'll discover later if/when we have longer values.
  21. So it looks like the "fix" is to CAST the fields that are causing problems. In this case, it looks like any of the 1000 character fields are causing problems. So a "fixed" query would look like this: SELECT OrderHed.OrderNum, OrderHed_UD.ShortChar06 AS 'SalesLeader', CAST(OrderHed_UD.Character01 AS varchar) AS 'JobName' FROM OrderHed INNER JOIN OrderHed_UD ON OrderHed.SysRowID = OrderHed_UD.ForeignSysRowID WHERE (OrderHed.OpenOrder = 0) Not really sure why this works, but it does. It's weird because one would think if there was a problem with the format of the field I wouldn't be able to pull it at all, but that's not true since, as described in the OP, I can run it without the alias on ShortChar06 and pull/display data from Character01 without any issues. Anyway, thanks for trying to help out!
  22. Do you have any recommended validators you prefer?
  23. I'm just going to throw some more information I discovered on here. Maybe something will spark a possible solution. I discovered that this behavior happens as soon as I add OrderHed_UD.Character01 to a query. I can pull in anything but that field. Same for Character02 and 03. Those three fields cause my queries to throw odd errors in PHP. At one point it even threw an "ambiguous column" error on a clearly defined column (it was JobHead.JobNum and there weren't even any other JobNum fields being selected). Here's the weird thing (or another one anyway): I can run these queries with the above character fields in ODBC Test Utility (its a utility built by Microsoft) and I don't get any errors at all. It displays the results, but the character fields above display their values as TRUNC: "" which I'm assuming means they were truncated to zero characters?? The character fields are all supposedly 1000 character text fields (I don't need that many that's just what was available; these were pre-created in the database for custom data).
  24. No worries. Honestly, being such a weird and inconsistent issue, I didn't expect to get an answer. A couple of quick Google searches hadn't turned anything up, so this was a shot in the dark hoping someone else may have had a similar issue. Leave it to Microsoft... 😅
  25. Of course it does. It's Microsoft. 😁 No delimiters gives the same result as using single quotes. It's really weird because I can pull the field with an alias as long as I don't have the Character01 field on there, which itself is using an alias. But it's not a matter of using multiple aliases in a query call, because some fields I can have a dozen aliases and they all work, but then they seem to reach a certain point and cease to function. I just don't know how to fully explain what's happening...
×
×
  • Create New...