Jump to content

kicken

Gurus
  • Posts

    4,695
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by kicken

  1. 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.
  2. 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>"); }
  3. Teaser could work too maybe.
  4. 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.
  5. 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.
  6. 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)
  7. 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).
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. By row are you talking about a <tr> table row? What's the HTML that goes along with that CSS?
  15. 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;
  16. 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.
  17. Unless you have code somewhere above that conditional that is doing $pageimg = $row['pageimg']; then the variable $pageimg is not the same as $row['pageimg']. That's why I asked to see how it's being defined. It seems to me like maybe you are expecting that $pageimg just magically exists because it's the name of a column in your DB table, but that's not how things work. If you don't assign a variable a value at some point, then it doesn't exist. And if it doesn't exist, then using empty() on it will always return true, which is the problem you seemed to be having.
  18. Where do you define the variable $pageimg then? Why are you using two variables instead of just the row result?
  19. The JS from my post only sets up the event handling for the click event. It still needs the copyToClipboard function from your original post to work.
  20. You don't have the copyToClipboard function in your code.
  21. It's generally better to just avoid ID's entirely. Use classes or your HTML structure to find the elements you need instead. Your HTML is hard to read being all in a single line like that, and using nl2br on a single line is fairly pointless. The code would be a lot nicer if you spaced it out and made it readable. You might then notice that you have an error in your HTML in that your copy button has two name attributes. Once that is all fixed up, you'd have something like this: echo " <div> <div class='copy-content'>".nl2br($row['info'])."</div> <br> <a href='updatecopypaste.php?id={$row['id']}'><img src='/ppreq/editbtn.jpg'></a> &nbsp &nbsp <a class='leftf' href='deletecopypaste.php?id={$row['id']}'><img src='/ppreq/deletebtn.jpg'></a> &nbsp &nbsp <button name='copy-button' class='unstyled-button' style='cursor:pointer'><img src='/ppreq/copybtn.jpg' border='0'></button> </div> <br><br> "; Your copy button and copy content are now wrapped in a common parent element, which will make it easier to locate one relative to the other. There are no more IDs so no more conflicts that need to be handled. The content is identified via a class and your button via a name, both of which can be duplicated. Now you need to create a single piece of JavaScript that can respond when any of the copy buttons are clicked. That JavaScript code would use the button that was clicked as an initial point of references in the document, and locate the content to be copied by looking for the element with the class copy-content contained within the same parent element as the button. window.addEventListener('DOMContentLoaded',()=>{ //Find all the copy buttons document.querySelectorAll('button[name="copy-button"]').forEach((button)=>{ //Add a click handler to each of the buttons button.addEventListener('click', (e)=>{ //Locate the copy-content element const copyContent = button.parentElement.querySelector('.copy-content'); //Do the copy copyToClipboard(copyContent); }); }); }); Example.
  22. The redirections are part of the setup for running a command. > and < tie the STDOUT and STDIN streams to a file. This processing is handled by the shell, not the program being executed, so they are not considered part of the programs argument list. Since this is pre-execution setup work as well, the redirection happens before the program is executed, thus happen even if the program execution fails. So, given the command line: zcho It is cold today! > winter.txt The shell would Parse the line into it's components Argument list: ['zcho', 'It', 'is', 'cold', 'today!'] Redirections: STDOUT -> winter.txt Setup STDIN, STDOUT, and STDERR STDIN: tied to the shell's current STDIN stream STDOUT: tied to a new stream created by opening winter.txt for writing (with truncation) STDERR: tied to the shell's current STDERR stream. Extract the first argument and use it as the program/command name (zcho) Attempt to execute the program/command with the arguments given You can confirm the redirection happens first by running your invalid command with STDERR redirection: kicken@web1:~$ zcho It is cold today! 2> error.txt kicken@web1:~$ cat error.txt -bash: zcho: command not found The error message from the zcho command is redirected to the error.txt file rather than displayed in the terminal.
  23. Why? It can be done in a round about and terrible way, if your version of MySQL is new enough. select * from ( select *, row_number() over (order by salary desc) as rowNumber, count(*) over () as totalRows from employee ) r where r.rowNumber = r.totalRows-3 It'd be far more efficient and easier to read just doing and ASC sort and taking the 4th row. You can't do a simple limit expression with a single query because the numbers in the limit cannot be column references. You have to instead find a creative way to count the rows then select the one you need based on that count.
  24. As far as I know, the standard allows for columns that are directly dependent on the group by columns to be used as well. For example, since orders.OrderId is a primary key, any other column in the orders table could be selected as well since there will only be one value for any given order id. The same would be true for customers.CustomerId and employees.EmployeeId. The way you are doing the joins would ensure there's only a single values from those tables for any given order ID, so in theory you could select any columns from those tables as well. In practice, whether a DB supports this type of analysis of the situation or not can vary. MySQL must support it to some extent. Microsoft's SQL server doesn't support it at all so you have to follow the rule of thumb describe above. I'm not sure about other DB systems. Since support varies, the safest thing to do is just follow the above rule of thumb and limit the select to your group by columns and aggregate functions.
  25. That when you use GROUP BY, the only columns that can be in your SELECT clause are Also listed in your group by clause or Used with an aggregate function so that multiple values get condensed down the a single value.
×
×
  • 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.