Jump to content

codefossa

Members
  • Posts

    583
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by codefossa

  1. To get a new number each time without some sort of bad luck, I would usually suggest using a timestamp.  It's in milliseconds in JS, so unless you go way overboard on a couple submits ...

     

    To skip the whole need of using random numbers to avoid caching, you could just use a post instead of get.

    $.post('/map_data.php', { 'mid': 1 }, function(data)
    {
        $('#summary').html(data);
    });
    

    Then you need to use $_POST instead of $_GET, but caching won't be an issue.  If you really did want a random number, PHP could generate that with rand().

  2. As an alternative to what's shown above, here's another option:

     

     

    <?php
     
    $start = 1;
    $end   = 5;
     
    // Using str_repeat()
    for ($i = $start; $i <= $end; $i++)
    {
    echo str_repeat('*', $i) . "\n";
    }
     
    // Going Both Ways
    $dir = 1;
     
    for ($i = $start; $i > 0 && $i <= $end; $i += $dir)
    {
    echo str_repeat('*', $i) . "\n";
     
    if ($i == $end)
    $dir = -1;
    }
     
    ?>
    
    The First Option Output:
    *
    **
    ***
    ****
    *****
    
    The Second:
    *
    **
    ***
    ****
    *****
    ****
    ***
    **
    *
  3. To pull the items of an array and append them to a string you would use: "your url ..." . $corpid[$x]

     

    Also note that you should probably check the array key exists, as you're doing 1 and 2 in your loop as $x when your array keys are 0 and 1.  Try something more like ..

     

     

    // Number of elements in the array.
    $corpid_len = count($corpid);
     
    // Loop through starting with 0 and ending with the count - 1
    for ($i = 0; $i < $corpid_len; $i++)
    {
    $url="https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID=" . $corpid[$x];
    }
  4. You are missing the period for $.getJSON().  If that's not your issue, you should check your JS console to see if you're failing to parse the return.  Maybe output the return in your console and see what that is.

     

    You can just do a $.get() and $.parseJSON() if you want to be able to output the data as well as parse it.

  5. Add some PHP to the top of your page setting the header to not cache the page.

    <?php
     
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
     
    ?>

    Or if you must use plain HTML.

     

     

    <meta http-equiv="expires" content="Sun, 01 Jan 2014 00:00:00 GMT"/>
    <meta http-equiv="pragma" content="no-cache" />
    • Like 1
  6. Good to know. But, with all due respect, what the hell were you even asking in your original post? :confused:  :happy-04:  I've reread it a couple of times and it still doesn't make any sense as to how it applies to what I now understand you were trying to accomplish.

    I'll just say exactly what I was doing then.  I have a table.

     

    id - timestamp - ip - user

     

    I get anywhere from a couple hundred to a 100,000 to add to it at any time.  I need to check if the ip/user combo exists before adding it.  The way I was doing it was sadly extremely slow because I wasn't aware you could do this, so I had to check if it existed the long way.

     

    So, you didn't really answer my question, but gave me an awesome alternative because now I'm able to just add them and it will take care of checking for duplicates.  I guess that's probably where the confusion was because you went in a bit of another direction and it happened to be exactly what I needed.

  7. Sorry for not saying it clearly but you've given me my answer better than I ever expected.  I didn't know you could use a combination of columns with UNIQUE so now, I can use that with INSERT INGORE and it's perfect. :)

     

    Thanks so much.

  8. It's set up with (id, ip, name) and I need to check that the ip and name combination don't exist before inserting.  I do this in one query (kind'a) but I would like to check more of them at once.  It sounds like you're saying to insert them all into another table, but that would add more time to this I would think?  Maybe an example of what you mean would help me understand.

  9. Is it possible to check if multiple rows exist at the same time.  For example, if a row with the id "1" and another row with id "2" exists, and return something like true then false if only the first exists?

     

    I have a file that provides tens of thousands to check and it takes forever.  I know this sounds bad off the start, but it's not something that is run normally.  Only to update my database with new additions.

     

    Is there any good way to check a lot at once?  I know you can insert many at a time and save a lot of time.

  10. Something like this would do it, but note that JS Fiddle won't allow you to get sent to another page.

     

     

    // http://jsfiddle.net/4d2xx7n1/
    $(document).ready(function()
    {
        var url      = "http://google.com",
            badImage = "http://darealtalk.files.wordpress.com/2013/02/smile.jpg";
        
        $("img").each(function()
        {
            if ($(this).attr("src") != undefined && $(this).attr("src") == badImage)
            {
                if (confirm("Image Found!  Click OK to redirect."))
                    $(location).attr("href", url);
                
                break;
            }
        });
    });
  11. That's because getTimezoneOffset() returns the offset in minutes rather than hours.  The pad() function you have there just repeats a string and adds it to the beginning of the string you give it, in this case the time.

     

    That shouldn't have changed the outcome of getTimezoneOffset() though.  It should have return something different if you changed your system's timezone.  For example, I get 240.

     

    One note.  Your line offset = ((offset <0 ? '-' : '+') + is wrong.  You want to switch the strings because 240 is GMT-4 and -120 would be GMT+2.

  12. You're better off not bothering with PHP.  Use Javascript.  You can make Greasemonkey scripts for your browser and that could handle it all.  Note that you should probably just keep track of cookies rather than your actual login information so the worst that can happen in most cases is session hijacking.  That can still suck, but usually not as bad as giving up your password.

     

    As for displaying it, you'd have several options.  Use any site and use their custom 404 page, or add something to the URL in the homepage likie "?action=dispalyInfo" and you can completely' wipe the page and create your own with JS.

     

    This is all client-sided of course, as I don't think you'd want to have your information available to remote users?  If you do for some strange reason, then I guess you could store it and use PHP, but I can't imagine that being your goal.

  13. If you meant you wanted the javascript outside of the body tag, then maybe this would be what you wanted.  Left the option for adding more JS after load rather than just one function called, but there's tons of ways to do that.

     

     

    <head>
        <script type="text/javascript">
            // Wait for load
            window.addEventListener("load", function()
            {
                // Do whatever ..
                getParameterByName("url");
            }, false);
        </script>
    </head>
    
    <body>
        <!-- Added "#" as target to avoid moving pages without JS -->
        <a href="#" id="urllink">Click Here</a>
    </body>
×
×
  • 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.