Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. Generally I only join tables in the same database, it's been a long time since I had to join tables from two different databases, but prefixing the table names with the database name and a dot should work. SELECT `w`.`title`, `c`.`name`, `c`.`lastname`, `c`.`str`, `c`.`nr`, `c`.`place` FROM `database1`.`client` AS c JOIN `database2`.`writers` AS w ON w.`id` = `c`.`id` WHERE `c`.`id` = 'qwert58efedd1979f'
  2. Transferring data between separate pages is part of the requirements for the assignment.
  3. $GLOBALS and global are both equivalent. Here's the same example using the global keyword: $varnames = array(); $vars = array( 'item1' => array( 'value1' => 'a', 'value2' => '' ), 'item2' => array( 'value3' => '', 'value4' => 'b' ) ); $result = array_walk_recursive($vars, function($item, $key) { global $varnames; if(empty($item)) { $varnames[] = $key; } }); print_r($varnames); The if() statement is there because you asked for elements that had an empty value. If you don't put the if() statement then all keys will be displayed (Except those keys that contained an array)
  4. I tested for myself and this works just fine $varnames = array(); $vars = array( 'item1' => array( 'value1' => 'a', 'value2' => '' ), 'item2' => array( 'value3' => '', 'value4' => 'b' ) ); $result = array_walk_recursive($vars, function($item, $key) { if(empty($item)) { $GLOBALS['varnames'][] = $key; } }); print_r($varnames); Displays:
  5. My example was not a solution to your problem, but an example on how array_walk_recursive works. I don't just make code to copy and paste. array_walk_recursive does not restructure an array, for that I'd suggest using loops, stacks or recursive functions. In PHP you cannot access global variables from within a function without using the global keyword or the $GLOBALS array.
  6. How exactly do you want the resulting array structure to look? In the callback, the first parameter is actually the value, the second parameter is the key. If you want to manipulate the existing array, make the parameter a reference using &. Any changes made to it will reflect in the array. This example prefixes all the array's values with "changed_": array_walk_recursive($insertion_vars, function(&$item, $key) { $item = 'changed_' . $item; }); print_r($insertion_vars);
  7. With pure Javascript there are two ways to transfer data from one page to the next: cookies and web storage. Cookies are an older technology so it's supported by older versions of Internet Explorer. Web storage is newer and easier to use and is supported by modern browsers. I would recommend using web storage. MDN has a good tutorial explaining how to use web storage: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API For your situation, it's better to use sessionStorage rather than localStorage. If you start off with a Javascript object, you can save it to your preferred storage method using JSON.stringify(). When retrieving the JSON string from storage you can turn it back into an object using JSON.parse(). As for how to get values from the radio buttons, give all the radio buttons the same name attribute and then use getElementsByName() to retreive the button elements, then loop through them to see which one of them has their checked property set to true.
  8. This seems to be a homework assignment, I would suggest using the technologies that have been taught to you instead of trying anything new that we might have presented to you here. I'm guessing that they want you to make a single-page application where the questions are given in an object (like JSON, but not necessarily a JSON string) and you go updating the page HTML generating form elements and reading them using Javascript.
  9. If that code really is inside the button click handler, you're not assigning an event to the file input until after the button is clicked. Event listeners should generally be attached in the global scope. Do you know what each line of that code does?
  10. You can store anything in a PHP session. https://www.w3schools.com/php/php_sessions.asp
  11. You don't need a new window, you could create a modal box instead. W3Schools even has a tutorial for that https://www.w3schools.com/howto/howto_css_modals.asp
  12. A pop-up window won't work if it's not called by a click event or keyboard event.
  13. If the window was stopped by a popup blocker that error will occur. For security reasons, most browsers will block a popup that wasn't created by a click or key event. The popup from your onload event will have that problem. Remove the onload event and just use the button. For efficiency, don't wrap event handler functions in function wrappers, they're not necessary. // Your current code: addEventListener("click", function(){yesClick();}); // Without function wrapper addEventListener("click", yesClick);
  14. What code did you try? The innerHTML property works on any element. var element = document.createElement("div"); element.innerHTML = "Text";
  15. It really depends on what order the resulting elements are in the HTML and what styles have been applied to the other elements. I would not set the margin to -100%.
  16. We don't know what your definition of "category" is.
  17. PHP runs on the server, generates the entire code for the page, then sends it to the browser. After that, the browser starts reading the HTML and running Javascript. If you're having trouble making sense of your code then you probably need to restructure it. Separate your code into pieces that each work on their own and put them into functions, then have a main program that decides which functions to call and what to do with the data they return. I checked your test page, but I don't know what to look for. The form validation appears to work properly. The language field doesn't get prepopulated after the validation fails but aside from that there's not a problem.
  18. PHP runs before the page starts loading. By the time any Javascript has started PHP has long finished. You can use AJAX to run additional PHP after the page has loaded. Since I don't know exactly what you're trying to do I can't give any suggestions. Usually PHP and Javascript shouldn't mix.
  19. The image on that example site is transparent. Download it and open it in a proper image editor. You can't selectively remove the white parts from your image using CSS. You have to erase it using an image editor.
  20. Your question is not very clear, so people haven't been answering. I suspect you want a dropdown menu. There are plenty of example of different CSS-based dropdown menus on this website: http://www.cssplay.co.uk/menus/
  21. Was the image transparent to begin with? If not, CSS has no influence on it.
  22. You can do it by using pseudo-elements to generate the arrow: h3 { position: relative; background-color: #00CC00; height: 50px; line-height: 50px; padding: 0 20px; max-width: 200px; /* Set width, float left or do something else to stop it it from taking the full width of the page */ } h3::after { /* This is a pseudo-element */ content: ""; display: block; width: 0; height: 0; border-style: solid; border-width: 25px 0 25px 25px; border-color: transparent; border-left-color: #00CC00; position: absolute; top: 0; right: -25px; }
  23. An iframe is the only way. Why don't you want to use an iframe?
  24. Here's how you created nested elements: /* Create a container */ var container = document.createElement("div"); /* Create children */ var image = document.createElement("img"); //... Set attributes var paragraph = document.createElement("p"); // ... Set attributes and content /* Add children to the container */ container.appendChild(image); container.appendChild(paragraph); /* Add the container to the body */ document.body.appendChild(container);
×
×
  • Create New...