Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    131
    Member #
    13656
    Greetings WDF Members!!
    I need some clarification on understanding includes
    <?php include("file.ext"); ?>
    Does this work like when you use a "src=" in the header section of a file. Like if I decide to put content in a table do I have to make a reference to a file that doesn't have the html and body tags. My understanding of this concept is that it kind of works like:
    <script language="javascript" src="file.ext"></script>
    and then not putting the <script> tags in the .js file?
    Next question. Is there a way to do includes from the client side? I have access to a PHP server, but I don't use too many PHP features and like testing locally as much as possible.
    Last question... How would I redirect an include (either PHP or JS) to a specific HTML element? What I am trying to learn is how I can create 1 page and everytime you link on a link on the navbar it changes the contents of a table cell. I know that I can accomplish this effect using layers and some javascript and create a tab kind of thing, but that affords a long initial load.
    Any advice is appreciated! Thanks in advance...

    ~darknailblue
    Christopher Carvache
    Web Developer / SEO
    Northeast Web Design
    +1.860.906.7802

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    You can use an include to import Javascript. However you shouldn't; using a script tag is better so the browser can cache it.

    You can do includes client-side (Ajax is somewhat based on the idea), but server-side is better in most circumstances.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Senior Member
    Join Date
    Aug 2006
    Posts
    131
    Member #
    13656
    Thanks for the response filburt, but I think you might have misunderstood one of my questions. My first question was asking if php includes work similar to the way you include a JS file in the <head> section of your page. I wasn't necessarily asking if I could use an include for javascript. My first question was if I needed to remove certain tags in the included file. For example when you include a JS file, in the included JS file you don't put <script> at the beginning and </script> at the end of the code. So would I have to remove the <head> and <body> and <html> tags in the included file?
    ~darknailblue
    Christopher Carvache
    Web Developer / SEO
    Northeast Web Design
    +1.860.906.7802

  5. #4
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    They do, but there are exceptions.

    Firstly, for HTML stuff you don't insert the html/head/body code. If you don't put them in the parent document, then put them in the included file. For example:

    PHP Code:
    <!-- Parent HTML file -->
    <html>

    <!-- no head tags because they are in head.txt -->
    <?php include('head.txt'); ?>

    <body>
    </body>
    </html>
    <!-- Included file (head.txt) -->
    <head>

    </head>
    See what I mean? You can wrap the tags around the include function and remove them from the included file, like with your JS example.

    If you want to include PHP within the document though, you need to put PHP tags in there (unlike linking to external JS), otherwise it's interpreted as HTML (it's done by default) and your PHP will be printed all over the page.

    All you need to do for that is, in your included file, put <?php at the start and ?> at the end, like you do normally. It's to tell the server there's PHP inside that file, not just text.

  6. #5
    Senior Member
    Join Date
    Aug 2006
    Posts
    131
    Member #
    13656
    Okay... thanks for the response and clarification. So lastly, if I wanted to create a document that worked kind of like a frames document in that when you clicked on a link on the navbar, it changed the contents of a particular frame, how would I accomplish that with tables or ? I assume that I would need to use some sort of JS function to change the contents of a table cell. Is that correct?

    ~darknailblue
    Christopher Carvache
    Web Developer / SEO
    Northeast Web Design
    +1.860.906.7802

  7. #6
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    That's correct. In-place updates without frames are only possible via Javascript.

  8. #7
    Senior Member Shani's Avatar
    Join Date
    Nov 2004
    Posts
    1,140
    Member #
    8171
    Quote Originally Posted by Shadowfiend
    That's correct. In-place updates without frames are only possible via Javascript.
    Really? I have never tried it, and I'll take your word for it since I'm not the best programmer, but logically, I don't see why you can't do that with php.

    Say each button of your nav has a value, and you have a spot (I'm thinking <div>, but I guess it could be a <td>) that receives the value to display different things. Am I making sense?

    Forgive me if my php syntax has errors, I'm still learning.

    PHP Code:
    <div id="<?php '$content_value' '>' . include ($content_value.txt?></div>
    Where $content_value is set by the nav button.
    Shani

    I have an eye for detail like you'd never believe.

  9. #8
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    That would work fine, but would require navigating away from the current page; thus why I said `in-place' updates, which I use to refer to updates that don't require leaving this page and going to another one :-)

  10. #9
    Senior Member
    Join Date
    Aug 2006
    Posts
    131
    Member #
    13656
    So could you give an example of an In-place update with JS?
    ~darknail
    Christopher Carvache
    Web Developer / SEO
    Northeast Web Design
    +1.860.906.7802

  11. #10
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    That's a complicated one. It involves three parts: the original page, the AJAX Javascript, and the remote page that returns AJAX information. I'd look it up online, there are many tutorials. It isn't all that big a deal, and there's also another post floating around on WDF from the past couple of days that has an AJAX example.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:22 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com