SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 49
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    main.php?page=blah part 2

    Seems I'm back again with another problem.
    Let me show you the script:

    main.php

    Link
    <a href="main.php?page=home">home</a>

    <?
    if ($page == home) {
    include("inc/default.inc");
    }
    elseif ($page == about) {
    include("inc/about.inc");
    }
    else {
    include ("inc/default.inc");
    }
    ?>

    default.inc

    Link
    <a href="main.php?default=news">news</a>

    <?
    if ($default == news) {
    include("inc/news.inc");
    }
    elseif ($default == about) {
    include("inc/about.inc");
    }
    else {
    include ("inc/default.inc");
    }
    ?>

    about.inc

    Link
    <a href="main.php?about=coc">coc</a>

    <?
    if ($about == coc) {
    include("inc/coc.inc");
    }
    elseif ($about == dis) {
    include("inc/disclaimer.inc");
    }
    else {
    include ("inc/aboutindex.inc");
    }
    ?>

    Problem
    Well Its like this every page works cept for the about.inc. Everytime I click a link on the about.inc it takes me back to the default.inc. How can I fix this problem?
    Note:
    The scripts and links are in seperate <td></td>'s

    Thanks you for your help I must hit school now

  2. #2
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't quite understand you, every time you click one of the about links you get taken back to the default about page?

  3. #3
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is one i wrote for my site awhile ago.. upload the php files in the same folder as the this file.. and you can just call it ?page=blah for .. blah.php pretty nice.

    PHP Code:

    <?php

    switch ($page) {
    //Content Pages
    case $page:
    $page $page ".php";
    if (
    file_exists("$page")) {
    include(
    "$page");
    } else {
    include(
    "default.php"); }
    break; }
    ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes Bob

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can anyone else please help me?

    I don't understand you Goldfinger

  6. #6
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whats in coc.inc?
    http://redgoals.com ... my site ... nuff said

  7. #7
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothings in the coc.inc its just apart of a site I'm doing why?

  8. #8
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    every time you link to main.php isnt the 'page=' part supposed to be in the url string?

    because if it isnt included the default.inc include is added:

    }
    else {
    include ("inc/default.inc");
    }


    what happens if you use main.php?page=about
    http://redgoals.com ... my site ... nuff said

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a better way of doing this? All this method has brong me was problems.

  10. #10
    SitePoint Zealot Nate's Avatar
    Join Date
    Sep 2001
    Location
    BC, Canada
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    seventhsign, Goldfinger's method is the bets method that you can use. If you make your query look like this:
    ?page=about
    It would load about.inc, but if you leave $page blank (or type in anything that doesn't exist), then it will load default.inc.

    Some interesting functions there... never seen switch() before.
    NATHAN WRIGHT
    PHP Developer, Simple Station

  11. #11
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well there must be something wrong with my coding or something because every page existed and it still took me to default.inc

  12. #12
    SitePoint Zealot Nate's Avatar
    Join Date
    Sep 2001
    Location
    BC, Canada
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure that all your links have been changed to use
    ?page=
    instead of the inconsistant variables that you were previously using?

    Also, why are you using switch? I looked at the PHP.net reference page for it, and you only have one case, so why not just use a single IF statement?
    NATHAN WRIGHT
    PHP Developer, Simple Station

  13. #13
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  14. #14
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm well I can't wait for the part 3. So Nate
    can plz help me again.

    What does Goldfinger mean by:
    ------------
    <?php

    switch ($page) {
    //Content Pages
    case $page:
    $page = $page . ".php";
    if (file_exists("$page")) {
    include("$page");
    } else {
    include("default.php"); }
    break; }
    ?>
    -----------

    Can you break it down for me. He probably thought I knew what he was talking about...well I don't

  15. #15
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe this will not help,
    but:

    >>if ($default == news)

    is better to put the string to check inside single quotes, such as

    if ('news' == $default)

    ( I inverted the order so if you forget to write == and write = instead you will have a parse error )

    using news without single quote PHP will treat it as constant, if that costant does not exist (ie news) then treat it as a string
    actually it works so, but as the manual says it is deprecated

    so if you before have something like
    define( "news", "ciao"); // << define a costant
    then the compare you did will never work.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  16. #16
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php 

    switch ($page) { 
    //Content Pages 
    case $page
    $page $page ".inc"
    if (
    file_exists("$page")) { 
    include(
    "$page"); 
    } else { 
    include(
    "default.inc"); } 
    break; } 
    ?>
    Ok let me break it down for you.. i edited this to work for inc files instead of php for you..so it should work.. copy all the php there and save it as index.php.. and have your original document that you want to show up when the user FIRST goes to your page as default.inc then when you want to load a page lets say you have a file named goldfinger.inc and you want to load that you call..

    index.php?page=goldfinger

    the script concatinates (dont know if that is spelled right not a word i use everyday.) the .inc to the page you specified so as you called ?page=goldfinger it takes goldfinger and puts the .inc on there for you.

    Next the script will check to see if goldfinger.inc does exist and if it does it will load that page in. Otherwise it will just load your default page..

  17. #17
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also try not having spaces in your files you are trying to call that will screw it up.

    Example:

    if you try and call

    ?page=blah blah blah

    the php script will look at it as..

    blah%20blah%20blah.inc and that doesnt exist.

  18. #18
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    k goldfinger I will try it out

  19. #19
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    usa
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey another thing goldfinger can you specify were the script can go look for the .inc files?

  20. #20
    SitePoint Enthusiast AmandaArias's Avatar
    Join Date
    Sep 2001
    Location
    Houston, TX USA
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php 

    switch ($page) { 
    //Content Pages 
    case $page
    $page $page ".inc"
    if (
    file_exists("$page")) { 
    include(
    "$page"); 
    } else { 
    include(
    "default.inc"); } 
    break; } 
    ?>
    I am probably wrong, but I would think to specify the location you could do this:

    $page = $page . ".inc";
    to
    $page = "folder/" . $page . ".inc";

    Or something like that. I may be wrong though.. but try it out and see if that works.

    Amanda

  21. #21
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you dont even have to do that amanda.. when you call teh script you can tell it where to go..like for exampe if i had goldfinger.inc in a folder called sitepoint i could just call..


    ?page=sitepoint/goldfinger

    .

    but if all your files are in one folder away from the root of your site. i woudl specify it..

    PHP Code:
    <?php 

    $folder 
    "name of folder";
    $cfold $folder "/";

    switch (
    $page) { 
    //Content Pages 
    case $page
    $page $cfold $page ".inc"
    if (
    file_exists("$page")) { 
    include(
    "$page"); 
    } else { 
    include(
    "default.inc"); } 
    break; } 
    ?>
    Last edited by Goldfinger; Mar 7, 2002 at 17:27.

  22. #22
    SitePoint Enthusiast AmandaArias's Avatar
    Join Date
    Sep 2001
    Location
    Houston, TX USA
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well that makes sense!!! Would my attempt have worked though? Just wondering...

    Amanda

  23. #23
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah it would have..but that can get messy.

  24. #24
    SitePoint Zealot Nate's Avatar
    Join Date
    Sep 2001
    Location
    BC, Canada
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still don't see the whole point of using the switch() function when there is only one case. Its used as an alternative for multiple IF's, correct? So why not just make it so its like this:
    PHP Code:
    <?php 
    if ($page) {
    $page $page ".inc"
    if (
    file_exists("$page")) { 
    include(
    "$page"); 
    } else { 
    include(
    "default.inc"); } 

    ?>
    I'm just wondering if thats a method that I should use more often...
    NATHAN WRIGHT
    PHP Developer, Simple Station

  25. #25
    SitePoint Enthusiast Goldfinger's Avatar
    Join Date
    Dec 2001
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that'll give you nasty errors. and you should use an

    if (isset($page)){

    if you were going to do it that way. but this way works so why fix it if it aint broken .


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
  •