Jump to content

Funce

Moderator
  • Posts

    602
  • Joined

  • Last visited

  • Days Won

    19

Posts posted by Funce

  1. The new expression produces an object using a Constructor function already defined (In this case, Chart). So if your second example works, it has to be defined elsewhere. (Hence I also wanted to make sure that the console was clear before attempting the second example)

    Are there any scripts that run on the page you're loading? Perhaps it's loaded there.

     

    Derp, Javascript is classless. Curse the PHP familiarity in syntax!

  2. I would think that this would depend on what scope you were using it in. 

    Is this run on a webpage? If so...

    • Is Chart.js included in your page? That would bring in all the class definitions so you wouldn't need to 'require'.

    You stated that this was in your browser console. Did you refresh the page to clear the console of imported modules after your first test?

  3. Yeap! You would be correct. I've now managed to get this to work. I'm instead using stream_socket_client in place of fsockopen. My local server doesn't have a proper certificate installed, so I've just currently made it ignore SSL verification.

     

    Thank you for the insight.

  4. I'm running into a few issues regarding my web application written in PHP.

    I'm wanting to post some data (already collected) without waiting for a response. I know that the page this posts to will take forever and a half to get through because it has to send multiple emails through a server that takes forever to do one. So I definitely do not want to block this page whilst the script is running.

     I looked around and I found this function, but I'm having some issues with it.

    <?php
    function post_without_wait($url, $params)
    {
    
      foreach ($params as $key => &$val) {
        if (is_array($val)) $val = implode(',', $val);
        $post_params[] = $key . '=' . urlencode($val);
      }
      $post_string = implode('&', $post_params);
      $parts = parse_url($url);
      $fp = fsockopen(
        $parts['host'],
        isset($parts['port']) ? $parts['port'] : 443,
        $errno,
        $errstr,
        30
      );
      if (!$fp) {
        throw new Exception($errno . ' - ' . $errstr);
      }
    
      $out = "POST " . $parts['path'] . " HTTP/1.1\r\n";
      $out .= "Host: " . $parts['host'] . "\r\n";
      $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
      $out .= "Content-Length: " . strlen($post_string) . "\r\n";
      $out .= "Connection: Close\r\n\r\n";
      if (isset($post_string)) $out .= $post_string;
      fwrite($fp, $out);
    
      fclose($fp);
    }
    ?>

    Whenever I use this, using my URL and the whole $_POST array,  I get

    HTTP/1.1 400 Bad Request Date: Fri, 31 Aug 2018 01:04:56 GMT Server: Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.5 Vary: accept-language,accept-charset Accept-Ranges: bytes Connection: close Content-Type: text/html; charset=utf-8 Content-Language: en Expires: Fri, 31 Aug 2018 01:04:56 GMT

     

    I can confirm that the page it is posting to never even runs, as I've set up an exception that is not being caught by my debugging tools.

    I'm using port 443 as it is my SSL port I'm running on. Port 80 gives me a 301 permanent redirect (I only want HTTPS, this is sensitive anyway).

     

    Does anything look amiss with the creation of this request?

  5. 1 minute ago, bartonlewis said:

    Thanks to you both for noting the missing braces.

    Thanks Funce for solving the problem, it worked.  It seems like the centre should be the centre - regardless of what margins you set - so I am not sure I am understanding this.  There appears to be some conflict with aligning items horizontally and setting left and right margins though.  

    No worries Barton. Your container was off to the left. So your text (centred on the container) was off to the left as well. The margins just created equal spacing on both sides of the container which ends up centring the container and fixing the issue.

  6. Thanks, John.

     

    I tend to only come here at the end of my workday when I've reached my wit's end with my own programs. Because of my TimeZone, sometimes it gets a little interesting, timewise. 

    I wish I could've saved you the trouble, but I'm glad its solved now.

  7. Hi there Roddy,

    I tested using Chrome (In its mobile emulation form) and using Chrome on my Samsung S9+.

    From what I remember from my cursory observation yesterday (or earlier today) one of your scripts, though I cannot remember which, was importing a new stylesheet which applied styles to your #middle element. The styles were never unapplied or otherwise overridden elsewhere. That would be the main issue for the colour changing. Have you seen the Jquery function AddClass? It's pretty helpful when you want to apply predefined CSS styles through Javascript.

    https://api.jquery.com/addclass/
    https://api.jquery.com/removeclass/

     

    I was unable to click on the links today to test, your overview.js has an error at line 423. You've commented out the beginning of a multiline comment block.

    • Like 1
  8. Hi there Barton,

    Are these snippets of your code? Some of the CSS braces aren't closed.

    In any case, your issue lies in the positioning of your flexbox element

    image.png.d4962c061437b656ea501a8b97883bdc.png

    The content is centred around the centre of your flexbox, but the centre is actually... well not at the centre. You can correct this by changing the margins on this particular style.

    page.html - line 207

    .flex1 {
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex;
      flex-direction: row;
      justify-content: center;
      margin: 5% 5% 0;
    }

     

    If you change the margin to:

    margin: 5% auto 0;

    That should solve your issue.

     

    I'd recommend some reading into margins to understand why it works. https://www.w3schools.com/css/css_margin.asp

  9. Have you had a look at Media Queries? I had a look on the website you linked, and if you investigate the styling on THIS element

    <nav class="w3-sidebar w3-collapse w3-white w3-animate-left" style="z-index:3;width:300px;" id="mySidebar">

    You'll find a media query that controls the sidebar. Having my screen maximised shows this style currently active upon it.

    @media (min-width: 993px)
    .w3-sidebar.w3-collapse {
        display: block!important;
    }

    This shows it from its hidden state, if the screen has a width of 993px or more.

    When I reduced the screen size, the active CSS changed to this instead.

    @media (max-width: 992px)
    .w3-sidebar.w3-collapse {
        display: none;
    }

    This hides the sidebar should the screen be less than 992px wide.

    I'm not brushed up on the :before and :after elements, so I wouldn't be able to answer that.

     

    If you wished to look at these styles in the source:
    w3.css, Line 793
    w3.css, Line 805.

     

    If you look around for these things in particular, you'll find a lot of other things are controlled by the screen size too

     

    Feel free to ask any further questions.

  10. Alternatively, you can access the server variable

    <?php
    require $_SERVER['DOCUMENT_ROOT'] . "/folder_above_root/file.php";
    ?>

    Its no good for creating HTML URLs but with that you can just make relative from root links by starting the URL with a '/'

  11. Hi there, m_hutchins

    script.js: Line 845

    values = [0, 576, 768, 992, 1200, 1600];

    script.js: Line 1124

    breakpoint: 992,

    script.js: Line 1175

    values = [0, 576, 768, 992, 1200, 1600],

     

    These might be the sizes you were looking for.

     

  12. <?php
    if (isset($_POST['croatie']) && isset($_POST['france'])) {
        $req = $bdd->prepare("SELECT parifoot.id FROM parifoot INNER JOIN foot ON (parifoot.id=foot.id) WHERE foot.active_fran_cro ='0' AND parifoot.id=:id ");
        $req->execute(array(
            ':id' => $_GET['id']
        ));
        $resultat = $req->fetch();
        if ($résultat) {
            $req = $bdd->prepare("UPDATE foot SET croatie=:croatie, france=:france, date_fran_cro=now(),active_fran_cro='1' WHERE id=:id");
            $req->execute(array(
                ':croatie' => $POST['croatie'],
                ':france' => $POST['france'],
                ':id' => $GET['id']
            ));
        }
    }
    ?>

    There was a few errors in your code, but I've fixed them up for you. I gather this was the top snippet of another bit of code, but my formatting tool doesn't work without closing braces so I apologize for changing it.
     

    Things Fixed:

    • You were missing ":" characters at the beginning of your bindings.
    • You needed an INNER JOIN where your first WHERE clause was going.
    • There were missing quotes, but that may have just been the translator
    • résultat requires a $ in php to signify that its a variable
  13. What part of this isn't working Rizwansyed?

     

    Is the value not showing up?
    Is the value incorrect?

    Can you edit into your post what you expect to receive, AND what you are receiving.

    This will let me help you a bit more.

  14. Could you clarify a little bit? I'm not sure what you are asking.

     

    If this is a certificate that represents your knowledge of HTML that you've achieved, it is usually preference whether you get it sent virtually or physically.

    I always go for both if able.

  15. Your alternative is to directly link menus to elements by referencing them correctly.

     

    Your code refers to situations such as

    <div class="menus">
      <ul>
        <li>Stuff to write</li>
        <li>More stuff</li>
      </ul>
    </div>

    If you change it to this you'll find that your code mostly works except for your last css block which should change to
     

    .menus a.active {
      background-color: #4CAF50;
    }

     

  16. On 7/7/2018 at 8:56 AM, Ayodeji said:

    I am working on a new website for my wife. I tried to make it mobile responsive by using the w3css collapsible navbar with its accompanying javascript and it was working fine. I later tried to make the navbar sticky to improve on the user experience. On introducing the sticky navbar with its accompanying javascript, it becomes sticky on both desktop and mobile but the menu button on mobile stopped working although it is displayed.

    file.html

    It seems you've defined `myFunction()` twice. When you're trying to make the page sticky, you've overridden the function which makes the menu work.

    I suggest changing the first `myFunction()` to a more descriptive name like `toggleMenu()` and change the menu button onclick method to also use toggleMenu.

  17. In most cases, mobile data is expensive and capped. If you go over the cap, its even more expensive.

    An Auto-disconnect timer protects your wallet should you forget to turn off your data, by turning it off for you when you're away from the computer for a certain amount of time.

    Computers (nowadays) have a large amount of programs that query to external servers in the background. If its left on all night, that can quickly add up if you're on a low capped plan. Especially if there are programs that like to update when your computer is idle.

     

    You will rarely, if ever, need more than 10 minutes. The only times this would be applicable is if you were downloading something particularly large that would take longer than 10 minutes. In that case I would recommend you to download it when you have Wi-Fi. (At home or with the free stuff you get around the place). 
    In any case that you would require more, it would be ill-suited for using the SIM data anyway.

     

  18. Use some Javascript for it.

    You'll need to change the `id` attribute for the A & B `<select>` element.

    To hide an option, all you need to do is change the `.innerHTML` property of the `<select>` to not include it. This can get messy, as if that option can reappear, then it needs to be stored somewhere else when you hide it.

    // On page load store an associative array of (value : innerhtml) with respect to each option
    
    //When the first dropdown is changed (function)
    //Get the corresponding values
    var value_thing = "A";
    var innerHTML_thing = "A";
    //Change the select to only display the value(s) applicable
    document.getElementById('units').innerHTML = "<option value='"+value_thing+"'>"+innerHTML_thing+"</option>";

    To disable an option, all you need to do is find out which option(s) (found in the `.options` collection) needs to be disabled.

    //When the other dropdown is changed (function)
    //Disable the options that aren't applicable
    document.getElementById('units').options[1].disabled = true;

     

    Those are the meatiest bits of Javascript you will need. Everything else, you already have the logic for in your post.

    (NOT TESTED SO BE SURE TO CHECK IT)

×
×
  • Create New...