Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: php script

  1. #1
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Cool php script

    right.......prob is below
    Last edited by JamieR; 10-19-2004 at 04:19 PM.

  • #2
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts

    this is my problem: -

    i'm trying to set up a archive page for my site. i have loads of plain html pages i.e. 12august04.html but i want to create a system using php where i can use this instead to call the script - archive.php?id=6 instead of having loads of php pages.

    The only thing is i dont want to use MySQL to call this - i just want to link loads of XHTML transitional web pages with a .php extension together by using the archive.php?id=6 call method to show each page as the id number changes.
    How do I do this, and can someone give me a PHP script to do this without usng MySQL?

    Regards
    -weazel

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A quick and easy solution:

    PHP Code:
    <?
    if($_REQUEST["id"]!="") {
      
    $page "pageName{$id}.html";
      include(
    $page);
    }
    ?>

  • #4
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    ok thanks but where "pageName{$id}.html" is, do I create put in "12August{$1}.html t show the id value?

  • #5
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not sure what you are trying to say. My guess is you wanna know how to access the filename. Personally I would do it this way:

    yyyymmdd.html

    so page id "20041008" would bring up 20041008.html which would be the file representing October 8th 2004.

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    It'd be better to make it:

    PHP Code:
    $id = ($_REQUEST["id"] != "") ? (1) : ($_REQUEST["id"];
    $page "pagename_" $id ".php";
    include (
    $page); 
    That'll check to see if $_REQUEST["id"] is set to "", and if it is it'll make it one, if not it retains the value. Then for the page names, it should be pagename_1.php (or whatever number it is).

  • #7
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    thanks but all i get is two of my web pages which I have called in the script being displayed on the page.
    What i want is :
    /archive.php?id=1 to show /20040901.php
    /archive.php?id=2 to show /20040902.php

    -weazel

  • #8
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Since you don't want to use MySQL you can create an array with the various filenames.

    PHP Code:
    <?
    $id 
    $_REQUEST["id"];

    $arrFile[1] = "20040901.php";
    $arrFile[2] = "20040902.php";
    $arrFile[3] = "20040903.php"//etc...

    if($id!="") {
      
    $page $arrFile[$id]
    } else {
      
    $page $arrFile[1];
    }

    include(
    $page); 
    ?>

  • #9
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Cool

    okay thanks for the help.

  • #10
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    it works but I have 2 pages one after each other, but the /archive.php?id=1 bit does work
    any ideas?

  • #11
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So you have 2 pages that you want to include on the same page?

    ie you want to include 20040902.html AND 20040903.html on the same page?

    if so...just alter the code this way:
    PHP Code:
    <? 
    $id 
    $_REQUEST["id"]; 

    $arrFile[1] = "20040901.php"
    $arrFile[2] = "20040902.php"
    $arrFile[3] = "20040903.php"//etc... 

    if($id!="") { 
      
    $page $arrFile[$id
    } else { 
      
    $page $arrFile[1]; 


    include(
    $page);

    //If you include 20040902.php ALSO include 20040903.php
    if($id=="2") {
      include({
    $arrFile[($id+1)]});
    }
    ?>

  • #12
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    no what i want is 20040909.html one one page as /archive.php?id=1 and 20040910.html as /archive.php?id=2.

    what i have at the moment is 20040909.html AND 20040910.html underneath the 20040909.html page which is being represented as /archive.php?id=1.

    I only want 20040909.html to be displayed as /archive.php?id=1 and 20040910.html to be displayed as /archive.php?id=2.

  • #13
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dude, then look at the original code I gave you.

    Code for archive.php:
    PHP Code:
    <? 
    $id 
    $_REQUEST["id"]; //$id will equal whatever you pass from the Query String

    $arrFile[1] = "20040909.php"
    $arrFile[2] = "20040910.php"
    $arrFile[3] = "20040911.php"//etc... 

    if($id!="") { 
      
    $page $arrFile[$id
    } else { 
      
    $page $arrFile[1]; 


    include(
    $page);  
    ?>
    This will do EXACTLY what you just said you wanted. If you want to access 20040910.html then visit: archive.php?id=2

  • #14
    Senior Coder JamieR's Avatar
    Join Date
    Oct 2004
    Location
    United Kingdom
    Posts
    3,161
    Thanks
    0
    Thanked 5 Times in 5 Posts
    thanks man but i've got a parse error on the code that you gave me:

    I have uploaded the array code you gave me to my web server:

    http://www.jamierees.co.uk/phparchive.php?id=3
    Please take a look and tell me what you think

  • #15
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's missing a semi-colon. I fixed it in the code below
    PHP Code:
    <?  
    $id 
    $_REQUEST["id"]; //$id will equal whatever you pass from the Query String 

    $arrFile[1] = "20040909.php";  
    $arrFile[2] = "20040910.php";  
    $arrFile[3] = "20040911.php"//etc... 

    if($id!="") {  
      
    $page $arrFile[$id]; //<--this was the line missing the semi-colon
    } else {  
      
    $page $arrFile[1];  
    }  

    include(
    $page);   
    ?>


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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