SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Shantra's Avatar
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to include contents?

    Hi,
    This is maybe a basic question for many, so I hope that you can help!

    My little problem is:
    I have a index.php file (main page) that has several include calls which works great. But now I want to include content into the index tables, called by klikking the menu links.

    Here is what I have made: (Don't laugh)

    THE LINKS
    <a href="index.php?content=links">Links</a>
    <a href="index.php?content=ads">Ads</a>

    CONFIG (is included at the start of index.php)
    <?php>
    $Content = '$content';
    if ($content = "") include ("index.inc"); // Included automaticly
    if ($content = "links") include ("links.php");
    if ($content = "ads") include ("ads.php");
    ?>

    INSIDE TABLE (where I want to include the content)
    <?php echo ('$Content'); ?>


    Thanks
    Last edited by Shantra; Jun 18, 2001 at 02:16.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here are a couple of points that may assist you.

    First in PHP (as in the C language) = is the assignment operator and NOT the equality operator. The equality operator is ==.

    foo == bar

    will evaluage to true if the LHV (left hand value) is equal to the RHV (right hand value) and false if the LHV is not equal to the RHV.

    Secondly, and this is a very technical bug in your code so don't dwell on it for too long ... but technically include() is not a function but a language construct. What this means is that you cannot write:
    PHP Code:
    if ($content == "") include ("index.inc");

    instead you must write ...

    if (
    $content == ""
    {
       include (
    "index.inc");

    Note the curly braces. It is good coding practice to use them whether they are technically needed or not.

    Thirdly, you can place include() in your code and the contents of the included file will only be included and executed if the program's execution path goes through the branch of logic containing the call to include()

    So, what I'm saying is that you can test for the value of $content and based on its value decide which file is to be included at the point where you want the content of that file to appear in your code. For example, a better way of writing that code would be:
    PHP Code:
    <?php
    if ( $content == '') {
       
    $file 'index.inc';
    }
    if ( 
    $content == 'links' ) {
       
    $file 'links.php';
    }
    if ( 
    $content == 'ads' ) {
       
    $file 'ads.php';
    }
    ?>

    ... and later inside table ...

    <?php include($file?>
    Does that help at all?

    Finally, I don't understand what you are doing with this line

    $Content = '$content';

    However, my advice is not to have different variables who's names only differ according to case - it is bad coding pracice - and easily confuses the easily confused such as myself
    Last edited by freakysid; Jun 18, 2001 at 04:50.

  3. #3
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you mean this:
    PHP Code:
    include($file); 
    not this:
    PHP Code:
    include($content); 
    Love it? Hate it? Helpful? Useless?
    Use the rate button to let me know what you think of my post!

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mia culpa - fixed now

  5. #5
    SitePoint Addict Shantra's Avatar
    Join Date
    Feb 2001
    Location
    Norway
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you VERY Much!

    Well, this was a real lesson for me freakysid!
    I remember in the good old days when I was programming in Basic (on the Commodore 64), then everything was much easier. Well I have forgotton it now. Time to learn something new like PHP. Thanks to you and some other people (like Kevin Yank), I think I will make it

    I guess that my link code was correct? Yeahaaa!!!

    PEACE!!


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
  •