Displaying multiples pages with one page

Discussion in 'PHP' started by tushardhoot1, Sep 12, 2007.

  1. #1
    Might sound confusing, but I want to display multiple pages depending on what option the visitor selects.

    Like, when the visitor clicks "buy something", then the page changes to display that page, while not redirecting to another page.

    Basically, the page checks to see what the user has chosen, and includes a file depending on what they chose. If they haven't chosen anything, then it displays the homepage.

    Anyone know how to do this?

    PS: I have a table. I am using the echo fuction to display it, and I wanted to put some php in the table. How do I do it?
     
    tushardhoot1, Sep 12, 2007 IP
  2. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes, it's done with javascript, and is commonly referred to as AJAX..

    You will need to learn javascript, and take a look at the jquerry (it's a javascript library) documentation. It makes it pretty easy.

    -Jason
     
    DopeDomains, Sep 12, 2007 IP
  3. DKameleon

    DKameleon Member

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    38
    #3
    Seems like DopeDomains is right.

    Here you can see simple AJAX example.
    You can check if it looks like something you need :)
     
    DKameleon, Sep 12, 2007 IP
  4. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Omg Dkameleon !!

    I'm a big fan of your site.

    Thanks guys, but like in my old arcade script (Av Arcade v3), it did some thing with the $_GET thing, where it would be like:

    if $_GET['addlink']
    include 'filename.php'
    else if $_get['deletelink']
    include 'filename.php'

    I'm not understand how that works...
     
    tushardhoot1, Sep 12, 2007 IP
  5. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    with $gets you will be doing page reloads.. Unless we both misunderstood the problem.

    Do you want it to display seperate content if you browse to:
    http://yoursite.com/
    and
    http://yoursite.com/?show=arcade

    but still have it trigger off one index.php file? (for examle http://dopedomains.com/?show=5Dict vs http://dopedomains.com/?show=5Len both run off a single index.php file, but the content changes because of the parameters. (before the PHP and SEO gurus yell, that's not how links are actualy displayed on my site, but it was the easiest way to illustrate examples)

    or so you want someone to browse to your page.. and then have part of the page contents (but only part of it) change as they click on various page elements? (For example http://dopedomains.com/ and click on the sorting. notice the page doesn't reload, but the content changes).

    -Jason
     
    DopeDomains, Sep 12, 2007 IP
  6. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    and the proper syntax for that example is:
    
    if (isset($_GET['addlink'])) {
       include('filename.php');
    } elseif (isset($_get['deletelink'])) {
       include('OTHERFilename.php');
    }
    
    PHP:
     
    DopeDomains, Sep 12, 2007 IP
  7. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #7
    YES! This is exactly it!

    Is there also a way to do this while keeping the SEO?

    Like, in my current arcade script, if SEO is on, it redirects to a page like site.com/category/page.html.

    It still keeps the same structure though. Only the middle screen changes, and no it doesn't use iframes.

    If you don't know how to do that, just show me how to do the ?show=page one please.
     
    tushardhoot1, Sep 13, 2007 IP
  8. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yes, you can keep it SEO friendly with some clever .htaccess (assuming your host supports it, and it sounds like they do).
    .htaccess example:
    
    RewriteEngine on
    
    RewriteCond %{query_string} ^(.*)$
    RewriteRule topic/(.+) /?topic=$1&%1 [nc,L]
    
    PHP:
    and the PHP code for it:
    
    if ($_GET['topic']=="addlink") {
    // Display Addlink code here
    } elseif ($_GET['topic']=="dellink") {
    // Display Dellink code here
    }
    
    PHP:
    to call them you would use http://domain.com/topic/addlink or http://domain.com/topic/dellink

    You can also add any paramaters you want to to the end with standard ?param=foo&p2=foo2 format.

    -Jason
     
    DopeDomains, Sep 13, 2007 IP
  9. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #9
    Ok, so if I have a link that says "Add a Link", where do I point that link to so it'll open up in the main page.
     
    tushardhoot1, Sep 13, 2007 IP
  10. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #10
    http://domain.com/topic/addlink
     
    DopeDomains, Sep 13, 2007 IP
  11. neelesh

    neelesh Peon

    Messages:
    141
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I use include('page name');
     
    neelesh, Sep 13, 2007 IP
  12. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #12
    I still don't understand...
     
    tushardhoot1, Sep 14, 2007 IP
  13. lwbbs

    lwbbs Well-Known Member

    Messages:
    331
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #13
    Use iframe to display the additional pages,
    Use javascript and CSS to display a tab menu.
    Click each tab to display different iframe. Add a close button,
    if user click the close button, then delete the iframe.

     
    lwbbs, Sep 14, 2007 IP
  14. booheadinc

    booheadinc Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    AJAX / DOM would be the best way to go.
     
    booheadinc, Sep 14, 2007 IP
  15. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Keep in mind that none of the dynamic methods to do this (ajax, iframes, frames) are SEO friendly.

    If that matters to you, you'll need to do a reload.

    DopeDomains presented what I think is the best solution for you in post #8.
     
    sea otter, Sep 14, 2007 IP
  16. DopeDomains

    DopeDomains Guest

    Messages:
    207
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #16
    SeaOtter,

    Thanks.

    If you code it right, with fall back for non-javascript you can have your ajax and SEO friendliness too!

    Dopedomains.com uses both SEO friendly URLs, and Ajax loading of content.

    -Jason
     
    DopeDomains, Sep 14, 2007 IP
  17. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #17
    So how does that work though?

    I put <a href=topic/addlink>, and then whenever someone clicks on it they'll just get index.php?view=addlink ?
     
    tushardhoot1, Sep 14, 2007 IP
  18. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #18
    A simpler version of the mod_rewrite (using QSA instead of manually adding the query string)
    RewriteEngine On
    RewriteRule ^topic/(.+)$ /?topic=$1 [NC,L,QSA]
    Code (markup):
    The users sees example.com/topic/addlink in the address bar when they click the URL but the server processes it as example.com/index.php?view=addlink

    And yes, DopeDomains is right, SEO and fallbacks for non JS users can be maintained when using AJAX, if you don't believe this, here is a starting point I use that seems to make the most sense:

    <a href="non-js-method-of-doing-the-same-thing.htm" onclick="alert('woot'); return false;">Do something exciting!</a>

    Or just look for "proper" web sites using AJAX.
     
    krt, Sep 14, 2007 IP
  19. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #19
    Wow, thanks, I'll try these out.
     
    tushardhoot1, Sep 15, 2007 IP