Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: PHP/JS on same page?

  1. #1
    Join Date
    May 2011
    Posts
    49
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default PHP/JS on same page?

    I have put a marquee on my home page with some scrolling text. I found some php code that would allow me to place text from a file into the marquee.
    Which is this.
    <div align="left" ><Font color="#000000" size="+1">
    <?php
    $myFile = "clientFTP/marquee.txt";
    $fh = fopen($myFile, 'r');
    $marquee_text = fgets($fh);
    fclose($fh);
    ?>
    <Marquee style="border:solid" bgcolor="#FFFFFF" direction="left" scrollamount="10" loop="2" width="90%"><Strong>
    <?=$marquee_text?></Strong></Marquee></font></div>

    I can run this on my home page by changing it to .php from .html and putting this line in the .htaccess file: DirectoryIndex index.php index.html

    That works, but now when the page is displayed, I lose my menu:

    <script type="text/javascript" src="ddlevelsfiles/ddlevelsmenu.js">
    </script>

    How can I keep the menu script working and use the php code above?

  2. #2
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    The <marquee> tag has been depreciated. The same effect can be achieved through many other means, but you shouldn't use the <marquee> tag.

    Same with the <font> tag. Use CssClasses rather than the <font> tag for the formatting of text.

    EDIT - You also have a lot of other minor depreciated markup. Can you post the whole page source code so we can get a better idea of what's going on.
    Last edited by jscheuer1; 05-12-2012 at 03:39 AM.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    same with the short echo tag ( <?= ).

    the PHP portion of your script should look like so (assuming the file path is correct):
    PHP Code:
    <?php
    //  PHP code should _always_ go at the top of the page.
    //  It is best practice to not send anything to the browser (echo, closing php tags, etc.)
    //     until _ALL_ of your PHP is finished.

    $myFile "clientFTP/marquee.txt";
    $marquee_text file_get_contents$myFile );
    // you might also want to check that the file was read successfully,
    //    and provide "default" text if there was a problem.

    //  later . . .
    ?>
    <!--html begins here-->

    <div class="marquee"><?php print $marquee_text?></div>
    You might look at Remy Sharp's marquee script to achieve the effect you want.

    (Don't be confused by the fact that his demo uses the <marquee> tag - the javascript removes it and replaces it with a <div> anyway. But -deprecated or not- it does provide a "fallback" for users that have javascript turned off.)

  4. #4
    Join Date
    May 2011
    Posts
    49
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    I often find that when I ask for help with this kind of stuff, people seem to be more interested in telling me why my coding is archaic or clumsy rather than offering meaningful assistance. I'm not a programmer, but I can usually find some examples of what I want and work through it. I don't care if the coding is up to date or elegant, I just want it to work. Here is the page with the marquee I am trying to automate. I think it looks and works fine, but I would like to be able to load the text from a file rather than have to edit the code directly.

    http://www.siftradingsystems.com/

    I'll take a look at the link and see if I can get where I want from there.

    Thanks for your help.

  5. #5
    Join Date
    Mar 2011
    Posts
    2,174
    Thanks
    61
    Thanked 121 Times in 117 Posts
    Blog Entries
    4

    Default

    I don't think you understand why we're telling you about your out-dated code. It may work fine in whatever browser you're using (I believe IE), but it can cause issues in other browsers (Compatiblity issues). You should always make your code completly cross-browser compatible because other wise you risk losing part of the potential market out there that wont be able to use your website properly.

    Also traq posted an answer to your original question (or at least enough to get you started).

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    indeed. your code being "up to date" or "elegant" has nothing to do with being nitpicky, and everything to do with making your code "work." Sometimes, the most "meaningful assistance" is to suggest an alternative approach.

    What happens if your code moves to a server (a new host, perhaps) that doesn't have the short tag enabled? Everything will stop working, and you'll have to go back and find every single <? ?> and change it.

    What happens if someone views you page in a browser that throws your page into quirks mode because of some deprecated element in the markup? It could break other things on the page (like scripts, for example), and it might be very difficult to discover the cause of the problem.

    My suggestion that your php code be separated from your html markup is all about practicality, as well: it's much, much easier to manage, update, and find and fix bugs that way.

    (It also makes you programs more flexible and robust, and helps you become a better programmer, but I didn't think that aspect was strictly relevant to your question. Things like deprecated elements and attributes certainly are relevant.)

    I can't tell from the snippet you posted, but it's entirely possible that the way you inserted the PHP block into your html page caused some kind of syntax error that's throwing a wrench into the works.

    What does your output HTML look like?
    Last edited by traq; 05-11-2012 at 02:06 AM.

  7. #7
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    I apologise for the way I came across. With depreciated code, there is a chance that your site will not look the same when it goes live than in a test environment. This is why I placed the caveat at the end asking for more code to work with. Archaic code can cause massive complications for debugging, and in forums like this we see archaic code every day that is actually the cause of the problems the questioner is facing. In a lot of circumstances, getting the code up to date and cross browser compatible is half of the battle. It may sound counter intuitive but as soon as the problem can be replicated on more than one browser, we can start to pick through and find the solution. Before that point it could just be bad markup that is causing the problem.

    I hope this helps your understanding.

    Check out http://validator.w3.org/check?uri=ww...ingsystems.com for an idea of how to streamline and best manage your code.
    Last edited by ApacheTech; 05-11-2012 at 02:42 AM.

  8. #8
    Join Date
    May 2011
    Posts
    49
    Thanks
    17
    Thanked 1 Time in 1 Post

    Default

    Just want to say thanks again for your help and sorry if I seemed ungrateful. I've been given a great deal of help here for which I'm most appreciative. I think I'm just to put the marquee idea aside for a while as it beginning to look a bit more complicated that I care to have to deal with.

  9. #9
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Don't give up! Your problem probably isn't really too difficult to solve. We're more than happy to help you through it!

  10. #10
    Join Date
    Apr 2012
    Location
    Chester, Cheshire
    Posts
    329
    Thanks
    7
    Thanked 35 Times in 35 Posts

    Default

    For your consideration:

    There was good reason why the <marquee> tag was depreciated that you might want to think about for your own site.

    * The moving text on the screen was found to detract from the rest of the site, causing users to focus mainly on one area of the screen. This was found to have a detrimental effect to the site as a whole.

    * Due to the way <marquee>s were animated, it caused very choppy movements across the screen. In extreme cases this was found to freeze the website and the browser and the flickering effect of the text as it moved was found to cause proplems for epileptic users on rare occasions.

    * Marquees caused major problems for screen readers and other methods of making webpages easier to use for disabled users. There was no indication of where in the outline of the page the <marquee> should be, this caused screen readers to interpret all <marquee> tags as Headings.

    I understand how you are trying to use the <marquee>, you're one of the rare cases who is using it for it's initial intended purpose; to act as a tickertape style news reel. There are some very effective methods of achieving the same effect in a valid way.

    This is one example:
    PHP Code:
    <form name="marquee">
        <
    input name="text" value=" Whatever text you type here will scroll">
    </
    form>

    <
    script type="text/javascript">
    //<!--
    /* Text box marquee by Dave Methvin, Windows Magazine
    May be used/modified if credit line is retained */

    var ScrollSpeed 100;
    var 
    ScrollChars 1;

    function 
    ScrollMarquee() {
        
    window.setTimeout('ScrollMarquee()',ScrollSpeed);

        var 
    msg document.marquee.text.value;
        
    document.marquee.text.value msg.substring(ScrollChars) + msg.substring(0,ScrollChars);
    }

    ScrollMarquee();

    //-->
    </script> 
    Last edited by ApacheTech; 05-11-2012 at 01:41 PM.

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
  •