SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member BillyBean2009's Avatar
    Join Date
    Jul 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php website problem..

    Ok I've got:
    <?php
    if($c == "events") { include "events.php";
    }
    if($c == "reviews") { include "reviews.php";
    }
    if($c == "interviews") { include "interviews.php";
    }
    if($c == "media") { include "media.php";
    }
    if($c == "radio") { include "radio.php";
    }
    if($c == "top10") { include "top10.php";
    }
    if($c == "forum") { include "forum.php";
    }
    if($c == "team") { include "team.php";
    }
    if($c == "songs") { include "songs.php";
    }
    if($c == "pics") { include "pics.php";
    }
    if($c == "video") { include "video.php";
    }

    else {
    else "main.php";
    }
    ?>
    but when I run main.php?c=reviews,it loads the reviews page properly, but alos add the main.php at the bottom again, Who can I stop it from running the main.php when I use the ?c=example. ??? If any could help. Thanks!
    Beyond Good.
    Beyond Evil.
    Beyond Your Darkest Imagination.

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I dunno about your problem, but I'd use this code (more efficient, I think):

    PHP Code:
    <?php 
      
    include($c ".php");
    ?>
    Now, that doesn't allow for the "else" part, but it's drastically shorter. If you want to keep the functionality identical, try this:

    PHP Code:
    switch ($c) {
      case 
    "events";
      case 
    "reviews";
      case 
    "interviews";
      case 
    "media";
      case 
    "radio";
      case 
    "top10";
      case 
    "forum";
      case 
    "team";
      case 
    "songs";
      case 
    "pics";
      case 
    "video";
        
    $txt $c;
        break;
      default:
        
    $txt "main";
    }

    include(
    $txt ".php"); 
    Good luck.

  3. #3
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your IFs except for the first have to be elseIFs.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As delemtri pointed out your else {} clause deals directly and only with
    PHP Code:
    if($c == "video") { include "video.php"


    else { 
    include 
    "main.php"


    And since $c does not equal video it displays main.php. I would use TWTCommish's code it is much cleaner and it will aleviate that problem of yours.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Member BillyBean2009's Avatar
    Join Date
    Jul 2001
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    THANK YOU!!!

    THANK YOU TWTCommish!!!
    That code seems to be way easier and cleaner for me. Thanks!
    and Thanks to everyone who helped me out before in my other post!
    Beyond Good.
    Beyond Evil.
    Beyond Your Darkest Imagination.

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: THANK YOU!!!

    Originally posted by BillyBean2009
    THANK YOU TWTCommish!!!
    That code seems to be way easier and cleaner for me. Thanks!
    and Thanks to everyone who helped me out before in my other post!
    No, thank YOU. You've just made my day.


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
  •