SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 49 of 49
  1. #26
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the switch function is basically the same as the select function in visual basic as it is an alternative way of writing if statments. It saves time on code for huge if statements and is actually a better way of writing most code (i find it that way anyway..)

  2. #27
    SitePoint Addict EreBuS's Avatar
    Join Date
    Aug 2001
    Location
    NY
    Posts
    202
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    goldfinger, is it better to configure my site using this method the ?page=whatever

    cause right now im using a different php file for all my pages, i got index.php, staff.php, articles.php, allarticles.php, should i just have one main page then include diff pages when the link is clicked?
    does this make sense,
    www.pcrivals.com is my site.
    Fragware - Hardcore PC Gaming and Modding
    SharkFOO
    - Spur Website Growth and Popularity
    Site5.com - Best Web Host on the Planet.

  3. #28
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a bit of a shameless plug here but ive used that method for my site link.

    i have my include files in one folder, i think it makes it easier to organise queries and other stuff.
    http://redgoals.com ... my site ... nuff said

  4. #29
    SitePoint Addict EreBuS's Avatar
    Join Date
    Aug 2001
    Location
    NY
    Posts
    202
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    w0rd, actually i just changed my site over to use goldfingers method, i like it a hell of alot more..
    Fragware - Hardcore PC Gaming and Modding
    SharkFOO
    - Spur Website Growth and Popularity
    Site5.com - Best Web Host on the Planet.

  5. #30
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Goldfinger
    PHP Code:
    <?php 

    switch ($page) { 
    //Content Pages 
    case $page
    $page $page ".inc"
    if (
    file_exists("$page")) { 
    include(
    "$page"); 
    } else { 
    include(
    "default.inc"); } 
    break; } 
    ?>
    Hi Goldfinger,

    I was able to use that quite effectively and I appreciate you taking the time to help with this.

    If you have a moment can you help with altering the type of file that this will work with.

    What I am trying to do is keep the default a php document, but link to an image.

    So, ?page=default would bring up the default.php document into the index.php page, but, if linked to /page=image.jpg

    I am trying to get image.jpg to include into index.php if linked in that fashion.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  6. #31
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seventhsign
    They said switch was just the same as if statement in this case so I just used it. I'll try and see if it works. Thanks All of you who helped me. If I'm still stuck watch out for main.php?page=blah part 3
    I think somebody shoudl write an article explaining it all..

  7. #32
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's pretty simple really, I am just receiving an error when trying to include "Just" an image.

    PHP Code:
    <?php

    switch ($page) {
    //Content Pages
    case $page:
    $page $page ".jpg";
    if (
    file_exists("$page")) {
    include(
    "$page");
    } else {
    include(
    "photosbeta.php"); }
    break; }
    ?>
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  8. #33
    ********* Genius zweistein's Avatar
    Join Date
    Aug 2001
    Location
    Croatia
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry if I'm breaking up an important discussion or anything, but I really don't see any sense in this main.php?page=something.
    Couldn't you just make a link to something.php and solve all your problems?

    Sorry if it's stupid, but I just don't get it.
    zweistein.web - tips&tricks for webmasters, music, programming, computers, Python, etc. new!!! English version, too!
    email | ICQ: 161202879 | AIM: zweistein2169

  9. #34
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you're not getting it.

    Why have seperate pages when you can have just one, and include content based on the link.

    That is the point of it.

    Instead of having complete pages written in php, you can have one.

    Want to add a new page? Just create new content and link to it from the main document which contains the code.

    www.808band.com is ONE page, yet it has pages and pages of content.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  10. #35
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by MBS
    It's pretty simple really, I am just receiving an error when trying to include "Just" an image
    You can't include() an image

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  11. #36
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    You can't include() an image

    Sean
    That's what I was afraid of =(
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  12. #37
    ********* Genius zweistein's Avatar
    Join Date
    Aug 2001
    Location
    Croatia
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by MBS
    Why have seperate pages when you can have just one, and include content based on the link.
    That is the point of it.
    Instead of having complete pages written in php, you can have one.
    So, you're saying that one file is serving as a template to others?
    zweistein.web - tips&tricks for webmasters, music, programming, computers, Python, etc. new!!! English version, too!
    email | ICQ: 161202879 | AIM: zweistein2169

  13. #38
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea, a simple html document.

    It is the template created simply in html with a PHP extension and the code embeded where I want the other pages content to be.

    Instead of creating multiple pages, I create multiple content includes.

    /page=content

    If there is a file in the same directory called content.php it will be included where the code is embeded on index.php and visa versa etc blah blah.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  14. #39
    ********* Genius zweistein's Avatar
    Join Date
    Aug 2001
    Location
    Croatia
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by MBS
    Yea, a simple html document.

    It is the template created simply in html with a PHP extension and the code embeded where I want the other pages content to be.

    Instead of creating multiple pages, I create multiple content includes.

    /page=content

    If there is a file in the same directory called content.php it will be included where the code is embeded on index.php and visa versa etc blah blah.
    Yeah, but what if I have a page with a 100 pages of content divided in categories? I.e. I have a Tutorials page and it links to other tutorials in the tutorials/ folder on my site. Then I'd have about 100 if-elseif statements!
    zweistein.web - tips&tricks for webmasters, music, programming, computers, Python, etc. new!!! English version, too!
    email | ICQ: 161202879 | AIM: zweistein2169

  15. #40
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No.. not the case, you're missing the point still.

    Try the code, stick it into an index.php page, create a default.php page, and then create a about.php page.

    Just use a small table with background color for default.phpa and about.php

    Load up index.php/?page=default

    Index.php will load the contents of default.php into the area of index.php you've placed the code above into.

    Then load up index.php/?page=about

    Youll notice that what is contained in index.php will wrap around the contens of about.php.

    Not sure if what I am telling you is making sense.

    See doing this,you can use a simple header, or any other type of include in index.php and any bit of content in any other page in that directory will be sucked into index.php if linked correctly.

    /?page= is essentially going to embed the content into index.php if linked to it in this way.

    Need to change the headers on 1 hundred pages, change the header.php include.

    Its one way of doing it and for me (Not having any ablity to database from scratch) this has worked out very well.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  16. #41
    ********* Genius zweistein's Avatar
    Join Date
    Aug 2001
    Location
    Croatia
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I still don't undestand this one:
    I have a page named tutorials.php which I linked as ?page=tutorials
    Now, on that page I have links to 50 tutorials I wrote and are located in a directory tutorials/.
    Can I link them like this:
    main.php?page=tutorials/html
    ?

    Thanks and sorry for the inconvenience .
    zweistein.web - tips&tricks for webmasters, music, programming, computers, Python, etc. new!!! English version, too!
    email | ICQ: 161202879 | AIM: zweistein2169

  17. #42
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can do that.

    If you have a page called templates.php and it includes 50 links, and you have another page called main.php, embed the switch code into main.php, and when linking you would

    main.php/?page=tutorialpage45 etc

    Templates.php can be anywhere.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  18. #43
    ********* Genius zweistein's Avatar
    Join Date
    Aug 2001
    Location
    Croatia
    Posts
    290
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by MBS
    If you have a page called templates.php and it includes 50 links, and you have another page called main.php, embed the switch code into main.php, and when linking you would

    main.php/?page=tutorialpage45 etc

    Templates.php can be anywhere.
    And what does the template.php page work in this case?
    zweistein.web - tips&tricks for webmasters, music, programming, computers, Python, etc. new!!! English version, too!
    email | ICQ: 161202879 | AIM: zweistein2169

  19. #44
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Based on your scenario, I answered the question.

    If you take the links out of tutorials.php and embed the switch code into tutorials.php, then save the links html into another document called lets says, links.php, when you go to tutorials.php/?page=links then the content in links.php will be included into the tutorials.php template if you will.

    The tuturials.php is the template for all other pages in this instance.

    You can use any page as a content template as long as you link it as such

    pagetemplate.php/?page=othercontentfilesforpagetemplate

    Not sure if that helps, but it depends on how you have your site put together in the first place.

    In 808band.com's instance the document root has a index.php page, in that page there is the switch code, where the switch code is located the other pages (about.php,contact.php and about 30 other pages) will dynamically include this content just based on the link

    www.808band.com/?page=about
    www.808band.com/?page=wallpapers
    www.808band.com/?page=booking
    www.808band.com/?page=sitemap

    The four content pages above have just a basic table, with css formatting, need a new page, copy one of them, create a new title image and fill it with content then link it from within the site with /?page=name

    Photos is a copy of the index.php page
    www.808band.com/photos

    Inside that folder is another index.php page with the switch code in it so it allows you to have categories represented by folders.

    What I eventually want to do is create a search engine for this type of custom site that search all text on every page EXCEPT index.php which as mentioned is just a template file with the switch code and all of the other includes, globalheader.php, header.php, nav.php, footer.php, right.php, left.php

    Not sure if I am still helping and starting to think I am rambling so forgive me for that, just trying to help you understand what has helped me a great deal about making and managing a large site with simple html php and css.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  20. #45
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to add the switch code again to one of the embedded pages?

  21. #46
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose some very talented person could define a nav, and body content seperately but Im not able to and in it's form no it's not possible from my tests.
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  22. #47
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    instead of writting the code of every page perhaps you should have nav.php file or something and just do an include at the top of your pages.

  23. #48
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe that is understood, and the point attempting to develop is a nav.php include based on the actual switch code page location.

    EX:

    If you are at /?page=default
    defaultnav.php is included, etc etcetc
    MBSHost.com
    http://www.mbshost.com
    Free signature/image hosting
    http://www.sighost.us

  24. #49
    SitePoint Member
    Join Date
    Apr 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry didnt read whole thread

    well this is what i did on mine, i created a a mysql table with all my links home/news/about and had it set with two values title (which is displayed on the page), then the page value so the title was 'About' and the page value was 'about'.

    I would then list the title's with the link as page value, so it would look like this.

    PHP Code:
    print"<a href=[whatever the phpself command is]?page=%s>%s</a><br>, $myrow[page]$myrow[title]"
    When doing this you would also be able to add, edit and remove the navigation in a control panel.

    You can also include if no results found show home page content or header redirect it to the home page content.
    Last edited by xdam; Aug 2, 2002 at 01:04.


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
  •