Jump to content

Ingolme

Moderator
  • Posts

    14,894
  • Joined

  • Last visited

  • Days Won

    176

Everything posted by Ingolme

  1. The way to solve it is to set the table headers outside of the loop, before the loop begins. In the case of your code it can be done near the line where $HTMLOUT_weeks is first initialized. # Array For Calendar // $weeks = []; // $week = ''; $HTMLOUT_weeks = []; // Creating an array. $HTMLOUT_week = ''; // Add weekdays header $HTMLOUT_weeks[] = '<tr><th>Man</th><th>Tir</th><th>Ons</th><th>Tor</th><th>Fre</th><th>Lør</th><th>Søn</th></tr>';
  2. You cannot return the data, you have to do something with it. Print it, manipulate it, store it into a variable or something else. In my previous example, I used console.log() to write the data to the Javascript console. Javascript is not allowed to write to files, neither on the server nor on the user's computer, but you can prompt the user to download a generated text file like this: <script> function file_get_contents(filename, callback) { fetch(filename).then((resp) => resp.text()).then(callback); } function handleResponse(data) { // This code generates a text file with the data and asks the user to download it var blob = new Blob([data], { type: "text/plain;charset=utf-8" }); var a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = "file.txt"; document.body.appendChild(a); a.click(); setTimeout(function() { document.body.removeChild(a); window.URL.revokeObjectURL(url); }, 0); } file_get_contents('https://mediainfo.tf1.fr/mediainfocombo/L_LCI?context=MYTF1&pver=4014002', handleResponse); </script>
  3. The code will need to be updated so that you are handling the data in the callback function. It actually cannot work identical to PHP's function because it's asynchronous. This would work: <script> function file_get_contents(filename, callback) { fetch(filename).then((resp) => resp.text()).then(callback); } function handleResponse(data) { // Do something with the data here console.log(data); } file_get_contents('https://mediainfo.tf1.fr/mediainfocombo/L_LCI?context=MYTF1&pver=4014002', handleResponse); </script>
  4. As I mentioned before, it's complicated. You'll first have to find the highest timestamp for each name, then attach this timestamp to all rows which have the name. Finally, you would sort by this timestamp first, then the other timestamp second. It most likely involves nested queries which are very slow, but there might be a more efficient method I'm not thinking of right now. This query might work. I wasn't able to test this because it looks like W3Schools' SQL editor doesn't allow me to experiment with nested queries. It might have a syntax error or result in duplicate entries. SELECT t1.ID, t1.NAME, t1.TIMESTAMP AS main_timestamp, t2.TIMESTAMP AS sorting_timestamp FROM table AS t1 JOIN table AS t2 ON ( t1.NAME = t2.NAME AND t2.TIMESTAMP IN (SELECT MAX(TIMESTAMP) FROM table WHERE NAME = t1.NAME LIMIT 1) ) ORDER BY sorting_timestamp, main_timestamp DESC I usually handle complex problems of this sort with the aid of a server-side programming language. Either doing two independent queries and using the results of one query as inputs to the next, or by just sorting the results manually after retrieving them from the database.
  5. The simplest solution would be to order first by name and then by time. [ ORDER BY NAME, TIMESTAMP DESC ] For your example data set the result would be identical to your expected result. It would get vastly more complicated if you want to order the names based on the timestamps attached to them.
  6. The browser should only care about the domain name, I'm not aware of any IP restrictions.
  7. CSS background properties do not apply to HTML images, only to files specified by the CSS background-image property. The <source> element doesn't have a background-image attribute, you need to use the src attribute instead. I don't think CSS styles work on <source> elements because they merely are used to identify a resource on a server, it's the parent <picture> element that needs the CSS styles. There is no equivalent of the CSS background-size: cover for HTML elements. I don't see a reason to use HTML for this problem, it would be best to just use the CSS background image. If you want different images based on screen size then you can use media queries. For widths, you can either choose to expand to fit the container or set a fixed value like 2000px; it doesn't make sense to have both. A full CSS example would look like this: .bgimg { background-position: center; background-size: cover; background-repeat: no-repeat; background-image: url("img/small.jpg"); min-height: 75%; } @media screen and (min-width: 601px) { .bgimg { background-image: url("img/medium.jpg"); } } @media screen and (min-width: 1501px) { .bgimg { background-image: url("img/large.jpg"); } } If you want to set the size of the background image for each screen size then you can put a background-size declaration in each media query. It does not make sense to use background-size: cover in this scenario because it will be overridden. Here's an example with a fixed image size per screen size. .bgimg { background-position: center; background-size: 600px auto; background-repeat: no-repeat; background-image: url("img/small.jpg"); min-height: 75%; } @media screen and (min-width: 601px) { .bgimg { background-image: url("img/medium.jpg"); background-size: 1500px auto; } } @media screen and (min-width: 1501px) { .bgimg { background-image: url("img/large.jpg"); background-size: 2000px auto; } }
  8. I'm not sure how the Safari console works, but look for a "net" or "network" tab in the console and see if anything changes in it when you click on the button which activates the sound.
  9. The path looks correct. Does it work when you put the audio file in the same folder as the HTML file? Are there any Javascript errors shown in the error console?
  10. When creating a cookie in Javascript, setting the domain component to your top level domain will make the cookie accessible to all subdomains. Here is an example: document.cookie = "username=John Doe; domain=example.com"; The above cookie will work on example.com and also subdomain.example.com.
  11. If the pages are on the same domain then they should already have access to the same cookies. Trying to preserve a session through query strings alone is very difficult and you can't guarantee that the session key won't be lost somewhere during the user's activity. There is also a security concern where, if somebody copies the URL and sends it to another person then that other person will have access to the same session. If you just want to direct the user to another page with a query string attached, you can use the location object. location.href = "somepage?var=value"; If you have a cookie's value stored in a variable (see how to get a cookie's value here) and want to send it in a query string then you can concatenate it to the string, using encodeURIComponent() to prevent malformed URLs. var cookieValue = "Pretend that this string came from a cookie"; location.href = "somepare?var=" + encodeURIComponent(cookieValue); If you actually want every link on your page to have a special query string attached, it will involve a lot of string manipulation, which is tedious. You will need Javascript to loop through every <a> element on the page (using document.getElementsByTagName("a")), check that the href property belongs to the same domain, then append your value to the query string to the URL and then assign the modified URL back to the link's href property. Useful string manipulation functions are shown here: https://www.w3schools.com/js/js_string_methods.asp
  12. You just need to break that down into its logical components. If you only want to test that field X is 1 when field Y is 1, it's like always returning true when field Y is 0 and only sometimes returning true when field Y is 1. The result would look like this: AND ( Y = 0 /* Value of field X does not matter when Y is 0 */ OR Y = 1 AND X = 1 /* Value of field X matters when Y is 1 */ )
  13. Just running that code in my own HTML document does not result in any errors. You shouldn't include the jQuery library twice. Either load it from the CDN or from your own server, but not both places. I would recommend loading it from the CDN for now to avoid errors with file paths.
  14. Looking at the HTTP headers, they are not permitting cross-origin requests on that file.
  15. Without seeing any of your code it is hard to know what is causing the problem. This could happen if your <script> tag occurs before the <script> tag which loads the jQuery library.
  16. Not from other websites. Browsers implement this restriction for security purposes. Applications that want to work around the restriction will have a back-end script which fetches content from other websites and sends it to the front end.
  17. As with all AJAX-style APIs, with fetch() you're only permitted to load files from your own server unless the target server has granted permission to your website.
  18. Because it is a very compact way to encode more than 256 unique characters. Most other popular encodings are single-byte encodings which only can represent 256 different characters. UTF-8 was designed to use multiple bytes to represent tens of thousands of characters, but it uses fewer bytes for characters which are assigned lower numbers. The first 128 characters are the same encoding as ASCII which helps with compatibility .
  19. Inline elements like <strong> do not handle margins and padding in the normal way. Vertical margin and padding are ignored. You have to set the display to inline-block to get normal behavior.
  20. I'm not sure what you need help with. At a glance, the code looks functional. Most of what you're talking about is back-end work, but you're only asking for help in the front-end.
  21. If the page is blank it means that your server has disabled error reporting. You can turn error reporting on for your page by putting these lines at the very beginning of the file: <?php ini_set('display_errors', 1); error_reporting(E_ALL); Error messages will help pinpoint exactly where the problem is and likely indicate how to fix it.
  22. Did you get any error messages? It's not obvious where the problem might be but there are a few potential problems in the code. The first thing that I notice is that the session_start() and header() are being called after HTML has been sent to the client due to the fact that the file which contains this code is included after some HTML in another file. session_start() and header() need to be called before and output, which could be HTML or any echo or print statements, among other things. The way to solve the above problem is to separate the code which generates HTML from the code which processes the form data. The code which processes the form should be included at the very beginning of pro.php. The other include statement embedded within the HTML could use variables created by the code at the top of the page to display information. The following line of code won't display an image because the src attribute is just "pro.php" which is not an image file: <img class="image-preview" src="<?php echo 'pro.php'; ?>" class="upload-preview" /> I think what you intended was to display the path of the uploaded image, which would be like this: <img class="image-preview" src="<?php echo $targetPath; ?>" class="upload-preview" /> Your code has some dangerous security holes. It allows for the possibility of hacking the database. Read about Prepared Statements to protect your website from that. Another security vulnerability is that people are able to upload their own PHP file to your server and run any PHP code they want. A common strategy to protect from this is to make sure that the file extension only is one of png, gif, jpg or jpeg. W3Schools shows an example of this on this page: https://www.w3schools.com/php/php_file_upload.asp To add an additional layer of security to the file upload form you could verify that the contents of the file is an image by using getimagesize().
  23. The stylesheet "table.css" is changing the colors. Also, one of the <li> elements has a style="color:black" attribute which forces the color to be black. We need to override these. This code will probably solve that: .day-odd li ul li { #33CC33 !important; } .day-even li ul li { color: #FF0000 !important; } .menu li ul li a { color: inherit; } This code is messy, but it is the only way to override table.css and your current HTML structure. You probably should learn CSS. If you did, then you would be able to analyze the problem and write the correct code without help.
  24. I don't know what you are trying to achieve. I see that the text color of the list items has been successfully changed on your website.
  25. Your CSS selectors are incorrect. You need to learn CSS properly. This will probably work, but I haven't verified what your HTML structure is. .day-odd li { color:#33CC33; } .day-even li { color:#FF0000; } li a { color: inherit; }
×
×
  • Create New...