Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. Why? You set the action as StoreTrue, which if you look at the documentation, Adding the flag multiple times just stores the value true multiple times. There's no such thing as "more true" and "even more true". If you keep reading that documentation, you'll find there's a different action type Counter which is what you want. It is documented as: The shown example is exactly what you are trying to do.
  2. According to the error, your code is calling $pdf->stream('example.pdf', 'I'); But if you check the Dompdf library code, you can see that the second argument to the stream function is supposed to be an array. What you want to do is pass an array with the key Attachment set to false.
  3. I'd suggest using the same markup with the radio buttons as the example. Just setup your secondary image display instead of using the borders. Updating the secondary image needs to be done with JavaScript, but it a relatively simple change event listener for the group of radio buttons. window.addEventListener('DOMContentLoaded', () => { const preview = document.getElementById('changeToPreview'); document.querySelector('.color-chooser').addEventListener('change', (e) => { const input = e.target; const img = input.parentElement.querySelector('img'); preview.src = img.src; }); }); Updated example.
  4. The radio buttons do not have to be visible, you can hide them and just have a label (which is your image) activate the associated radio. I put together an example. <input type="radio" name="color" value="black" id="black"> <label for="black"> <img src="black.png" alt="black"> </label> You can use CSS to display a border around whichever image is selected, and if you add a class to indication the current one, use a different border to indicate the current item. In my example above, the selected item has a white border, the current has a yellow border.
  5. Are you set on doing it this way? You could instead use a set of radio buttons with a highlight around the color selected and eliminate the need for JavaScript.
  6. There are no internals of spl_autoload_register with regards to the locating and loading of a class. All the details of how that is done is up to the function you provide. All spl_autoload_register does is add your function to a list of functions that get called when an unknown class is referenced. Your function gets the fully qualified name of the class and has to use that to define that class, typically by converting the name to a file location and including that file. Your example essentially just uses the class name as-is as a file path and attempts to include that file. Since your class is defined as Hello then you get a filename of Hello.class.php with a capital H. Your actual filename however seems to be hello.class.php with a lower-case H. On a case-insensitive filesystem such as windows' ntfs, this would be fine and the file would be loaded. On a case-sensitive filesystem such as linux ext4, this is a problem and the file will fail to load. As mentioned, typically one would just use composer to handle class autoloading rather than defining your own function. Combine it with the PSR-4 standard (and ensure you get your case correct) and you mostly don't have to think about it at all.
  7. Some filesystems are case-sensitive, so Hello.class.php and hello.class.php are two completely separate files. You need to either ensure you are using the correct case when creating and referencing your files, or normalize the case in some way (such as making everything lowercase).
  8. I don't understand what it is you're saying is wrong. You should create a fiddle that reproduces the problem and post the link. Then re-describe the problem, optionally with screenshots if you can't describe it well. Your HTML is currently invalid due to a missing quote, you should fix that as well.
  9. Been a long time since I used a positioned popup window. Had to check the docs for the right options. You can center the popup on the screen by setting the top / left options. These control the top-left corner of the window, so to get it truly center you have to calculate the right offset. There's a standard formula for this. centerPoint = (sizeOfContainer - sizeOfThing) / 2 For this case, your sizeOfContainer is the screen width/height and the sizeOfThing are your popup window's width/height. Run that formula for each to get your top/left values and set them in the window options. const popupWidth = 400, popupHeight = 800; let top = (window.screen.height - popupHeight)/2; let left = (window.screen.width - popupWidth)/2; const win = window.open('', 'formpopup', 'width='+popupWidth+',height='+popupHeight+',resizable,scrollbars,top='+top+',left='+left); The final result may be slightly off (mostly in the height axis) due to the window UI elements since they are not part the calculation. The width/height you specify is for the content area of the window, the UI elements are added on top of that. If the slight offset bugs you, you can fix it after opening the window by re-calculating the offset using the window's outerWidth and outerHeight values for sizeOfThing, then using it's moveTo function to re-position it. top = (window.screen.height - win.outerHeight)/2; left = (window.screen.width - win.outerWidth)/2; win.moveTo(left, top); That may create a noticeable jump after the window opens though.
  10. The empty string ('') will compare correctly using ==, because it's a string. This issue is specifically when you are testing a numeric value against a string. Somewhere in your code $sw is getting set to the numeric value 0 and not the empty string as you thought and that's what lead to the problem. In general, using strict comparison is a good habit to develop to save help ensure you're dealing with the correct types.
  11. You're probably running a version of PHP before 8.0 and suffering from it's poor handling of comparing integers and strings. This was changed in PHP 8.0 to something that makes more sense. Compare the output if you run the code on various versions of PHP: https://3v4l.org/vLB4b The simple fix is to perform a strict comparison using the === operator instead. if($sw === 'B'){ print("sw=$sw<br>"); print("<font color=maroon>Buy $amt <font color=red>$sw<br>"); }
  12. Teaser could work too maybe.
  13. PHP allows extra values to be passed to a function. You can use func_get_args to obtain these values within the function and do something with them. This is the original way of creating a variable-length argument function.
  14. There's no hidden parameter feature reference. The issue you have is a very common one among new developers, and that's knowing the difference between a function reference, and executing a function. function myFunction(){ //do stuff } thing.addEventListener('click', myFunction ); //<- pass a reference to myFunction thing.addEventListener('click', myFunction() ); //<- execute myFunction now, pass it's return value. addEventListener wants a callback function, which needs to be passed as a function reference. To do that, you only supply the name of the function (or an inline anonymous function). Adding the parenthesis after the function name causes that function to be executed rather than referenced. When you're passing a function reference, you cannot pass any parameters along with that reference, which is what you were trying to do. In order to supply parameters, you need to use the anonymous inline function as a wrapper. The anonymous function is passed as the real event handler callback, and when the event occurs and the anonymous function is executed, it in turn executes your desired event handler with the proper parameters.
  15. In that line, you are not assigning the toggleBtn function as an on-click event handler. You are executing that function now and assigning whatever value it returns (which is nothing) as your on-click handler. You need to wrap it an anonymous function which is passed to addEventListener as the click handler. item.addEventListener('click', function(){ toggleBtn(item,index,arr); }, false)
  16. What you downloaded is the source code of the software. You need to compile it to get an actual program you can use. You can do that relatively easily on Linux since that's the environment it was designed for. Whether it can be done and how difficult it would be to do on Windows is unknown. Something like MinGW might help. A .md file is just a text file. Any text editor will open and display it just fine. It might not open with a simple double-click as the .md extension probably is not registered, but you can always open the editor and use it's file->open command (or just rename the file to .txt and double-click).
  17. An object-oriented approach has a lot of benefits over a functional approach, particularly when paired with a good IDE. Autoload support If you structure your classes according to the PSR-4 standard, you can let an autoloader script manage including your classes when needed. This means you no longer have to manual deal with making sure you have included the correct files on your pages, or just include everything to be safe. You can just use your classes as needed and let your autoloader script automatically include the class file when necessary. Autoloading of functions is currently not possible, though that might change eventually. Data management Something every program needs to do is manage and work on data. With a functional approach, that often means you use a lot of associative arrays to hold your data and pass those array's between functions. While this works, over time it becomes hard to manage as you will loose track of what keys exist in what arrays and different code paths may end up diverging in how they manage those arrays. Even using just simple objects can help with this by providing predefined properties for your data structures. When paired with a good IDE, you will be able to able to easily see what properties are available on an object, get auto-completion of property names as you code, and easily refactor the data structure if necessary (ie, rename a property). Automated Testing OOP lends itself well to automated testing thanks to features like interfaces and inheritance. With functions, you end up with hard-coded references to other functions through out your code. The implementations of those functions cannot be easily changed for testing. By passing around objects and calling methods instead, you can easily replace your real object with a fake / mock object for testing purposes. To take full advantage of this, you need to not just use OOP, but also techniques like dependency injection so you don't just replace a hard-coded function with a hard-coded class reference. Reuse While both functions and classes allow one to re-use code, I generally find that making reusable code is easier done using an OOP approach. Often in order to be reusable, code needs to be flexible. To manage that with functions you either end up making a lot of different functions, or your functions need to have a lot of parameters (or a single large array parameter) to control the functions behavior. This leads to a messy code base and can make future edits hard to make without inadvertently affecting some use case. With an OOP approach, you can control behavior though either properties that can be set individually as needed, or by breaking things down into various objects that can handle different use cases. This lets the code be cleaner by removing various conditional branches and helps isolate future changes to specific areas without affecting other areas. You need to know OOP anyway. The vast majority of libraries out there are using OOP, so if you want to take advantage of other peoples work to save yourself time (ie, the various frameworks or even just individual libraries) you need at least a basic understanding of how OOP works. You don't need deep knowlege of everything OOP and all the design philosophies t hat go with it just to use a few libraries, but you do need basic syntax and structure knowledge to understand the library code and know how to interface with it. The more you know though, the easier it is to integrate with libraries and customize them to suit your needs.
  18. As has been said already, Webalizer is pretty much a dead project. The FTP server is apparently no longer running so you cannot download from it. If you really want a copy you can get it from the internet archive using the wayback machine. https://web.archive.org/web/20150905053743/http://www.webalizer.org/download.html Unless there is some specific reason you must use Webalizer though, you should probably look into a modern alternative.
  19. From the PHP perspective your dummy column is the same as any other column. If you want to echo it, you just echo $row['dummyColumnName']. You probably don't want to echo it though, you want to use it to determine which table the row came from using a simple if. if ($row['dummyColumnName'] === 'A'){ //$row is from the first table } else { //$row is from the second table. } I suspect you might not understand what a union is for. Generally speaking, you shouldn't need to use a union. If you do, it might be a sign that you're database design needs to be re-worked. There are some reasons for it's use, but they are not all that common. I don't know your data or what you're trying to do but I'd guess that a union select probably isn't the right solution.
  20. You might be misunderstanding what ::before does, or maybe my usage of parent. The selector ::before is a pseudo-element that is placed before the content of the selected element, not before the actual element. For example, the html: <div class="hello">World</div> With the CSS .hello::before { content: "Hello"; } Would be rendered as if you had written this HTML <div><span>Hello</span>World</div> The pseudo-element is a child of the selected element. As such, any padding on the selected (parent) element affects where the pseudo-element is rendered.
  21. For the section of the page you're showing, the problem is that your background issue is absolutely positioned over top of the ::before element. You can work around this by adding to your style position: relative; z-index: 10; That will make the gradient show, but it won't be positioned correctly due to the padding on the parent element. You'll need to adjust that styling to get what you want, and probably other page styles.
  22. You probably need to update your php and/or openssl and/or libssh versions. The error is likely because your client does not support any crypto algorithms that the server does so the encrypted channel cannot be established.
  23. By row are you talking about a <tr> table row? What's the HTML that goes along with that CSS?
  24. From the manual: So when you're dividing your timestamp variable, you get a floating point number due to the values not dividing evenly. Attempting to use % on that result causes PHP to convert it to an integer instead, loosing whatever fractional value existed in the process. In the past, this happened silently. Now there's the notice about it to highlight the potential bug. Convert your floating point value to an integer value yourself explicitly to remove the error. You can do this in that code by just changing the floor function to only operate on the division instead of the whole expression. $hours += floor($timestamp / 3600) % 24; $min = floor($timestamp / 60) % 60;
  25. There is a concept in design/engineering called Hysteresis. In a nut shell, you don't define hard cut-off points and instead define a range, or introduce a delay of some sort. So instead of having your code hide the menus when the container is <50 px from the top and show them when 50px or more from the top, you instead set it up such as: If container is <50 px from the top, hide the menus If container is >150px from the top, show the menus. If the container is between 50px and 150px from the top, just maintain whatever the current state is. The range can be fixed like the example, or dynamic by calculating the menu heights. You just need the range to be large enough that toggling the visibility of the menus doesn't cross both boundaries.
×
×
  • 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.