SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to call this script with javascript.

    <?php
    $getfile = rand(1,10);
    $includefile = "file" . $getfile . ".txt";
    include ($includefile);
    ?>

    Hello is it possible to give this php script an id so I can call it separately with javascript? I want the javascript to keep executing it over and over. Please let me know, thank you very much.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, but are you sure that's what you need to do to accomplish your goal? Please don't cross-post on multiple forums.

  3. #3
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is wrong? This has to do with both javascript and php so I am trying to get help. When I post it in php they tell me to post it in javascript. When I post it in javascript they tell me to post it in php. Since that is what I am being told I have to post it in both.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That's because you won't explain what you really want to do so someone can help you.

    What do these files contain, why do you want to repeatedly do whatever they do, and what do you mean by "include it over and over" (infinite loops are BAD)?

  5. #5
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I include plenty of information saying exactly what I am looking for. I say what timing functions I am doing and what my random functions are. If you don't know what random strings are or timing functions are its not my fault.

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I know what random strings are and I know PHP, JavaScript and AJAX. However, I'm not going to write code that might be far from optimal for your application because you won't describe what you're actually doing.

    Do you see anyone else helping?

  7. #7
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey guys ... don't fight with each other. relax

    1Jen .. can you please explain what you meant by "give this php script an id" ?
    What i understand is ... every time this page is opened a random file is displayed to visitor. Am i right?
    And with javascript you want a new file is show to user after some time?

    if i am wrong - correct me.

  8. #8
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You got it right and thanks for keeping the peace. I'm taking a break.

  9. #9
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay then you don't need to modify php code. The same code will remain in the file. You will only need a javascript that will refresh the page every 15 seconds or what ever time interval you want. After page reload ... automatically php will include another random text file.

    Here's the javascript code with your php that will refresh the page.

    <html>
    <head>
    <script type="text/javascript">
    onload = function() {
    setTimeout("window.location.reload()",5000);
    }
    </script>
    </head>
    <body>
    <?php
    $getfile = rand(1,10);
    $includefile = "file" . $getfile . ".txt";
    include ($includefile);
    ?>
    </body>
    </html>
    Is it what you wanted?

  10. #10
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect! Thank you very much.

  11. #11
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    welcome 1Jen


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •