www.webdeveloper.com
Results 1 to 3 of 3

Thread: [HELP] Show selected content from HTML in PHP

  1. #1
    Join Date
    Feb 2014
    Posts
    2

    Question [HELP] Show selected content from HTML in PHP

    Hi,

    I would like to create a page that has "similar" functionality like 'Facebook'. What I mean is the dynamic page in center that shows you posts from another people etc.. Basically, create one page that stores all stuff to be shown and second one that shows it.

    The page would look like this:
    Top banner and menu alongside with side panel are fixed to page. In between them is frame, that displays "content; a "content.php". This "content.php" gets its content to show from source file "source.html". Source.html stores all information/ data that has to be shown through "content.php" in from of <div> tags (blocks). So it is like this:
    main page + content
    Code:
    <body>
    <a href="content1" target="frame">link to content1</a>
    <a href="content2" target="frame">link to content3</a>
    <a href="content3" target="frame">link to content3</a>
    ...
    <iframe id="frame" src="centent.php" name="frame"></iframe>
    <(body>
    source
    Code:
    <body>
    <div id=content1>Content to be shown</div>
    <div id=content2>Content to be shown</div>
    <div id=content3>Content to be shown</div>
    ...
    </body>
    So if I click the link "content1" on main page, the "content.php" will take info/data from "source.html" that is listed as "content1" and shows it in the frame. Not entire "source" page, only part that is listed as "content1".

    The question is, how do I do it?
    The page isn't that much problem as the PHP. I know there are these stuff in PHP (in between body tags are these <? ?> ), but i don't know what tags / how to use them to show only a certain content (div/block) from file.

    Maybe you're asking: "why don't you create separate pages for each content?" (like content1.html, content2.html...) The reason for this is, I'm making a school project and I have to use PHP and I don't know where to use it. And secondly, if every page would have their own file, I would lost track of it. So that's why I want to use it this way.

    Can someone help me, please?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,330
    Here is a (crude) example of how you can drive everything from one PHP page:

    index.php:
    PHP Code:
    <!DOCTYPE html>
    <head>
    <title>Test</title>
    <style type='text/css'>
        body {
            overflow: auto;
            margin: 0;
            padding: 0;
        }
        #sidebar {
            float:left;
            width:150px;
            margin: 0;
            padding:1em;
        }
        #content {
            float: left;
            margin: 0;
            padding: 1em;
        }
        #head, #foot {
            margin: 0;
            padding: 1em;
            clear:both;
        }
    </style>
    </head>
    <body>
        <div id='head'>
            <p>Static stuff at top of page goes here.</p>
        </div>
        <div id="sidebar">
            <p>Static stuff at side of page goes here.</p>
        </div>
        <div id='content'>
    <?php
    // put dynamic content here, based on URL 'page' parameter
    $page 'default.html';
    if(!empty(
    $_GET['page'])) {
        if(
    file_exists(basename($_GET['page'].'.html'))) {
            
    $page basename($_GET['page'].'.html');
        }
    }
    readfile($page);
    ?>
        </div>
        <div id='foot'>
            <p>Static stuff at bottom of page goes here.</p>
        </div>
    </body>
    default.html:
    HTML Code:
    <h1>Default Content</h1>
    <p>This is a test. It is only a test.</p>
    custom.html:
    HTML Code:
    <h1>Custom Content</h1>
    <p>This is another test. It is only a test.</p>
    If you call index.php with no additional parameters, you will get the default content. If you call it as index.php?page=custom, you'll get the content in custom.html.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2014
    Posts
    2
    It's woks better than I wanted

    THANK YOU

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles