not sure what to call this script

Discussion in 'PHP' started by Joobz, Jun 18, 2007.

  1. #1
    but I am looking for a php script that is only one page (or one document). You set it as index.php and place it in your root domain. Then when someone navigates to a link such as:

    www domain.com/123456.htm

    the script will read the document number (the 123456.htm part) and go to a mysql database and pull record number 123456 and output the row to the variables which in turn populate your template.

    I guess it might work like some of the domaintools sites where you append the root with a /somethingelse and it pulls in the somethingelse

    Anyone know where I can get this - or even what it's called?
     
    Joobz, Jun 18, 2007 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    I dunno if you'll find something premade, it's a mixture of mod_rewrite php and mysql, ( as you prolly know ).

    Do you know how to program or do you want actual code ?
     
    krakjoe, Jun 18, 2007 IP
  3. Joobz

    Joobz Peon

    Messages:
    598
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am stronger in desktop admin scripts (wsh, vbs, wise setups, wrappers, etc) trying to learn php so you could say I pick up a thing or two from seeing a script but to write one from scratch is whole different deal.

    I was just wondering if there was something on hotscripts or one of those sites - not sure what to call it though.
     
    Joobz, Jun 18, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    It is hard to find something for just this. Maybe a tutorial on mod_rewrite but that is about it. Finding a script will find this implemented in an app and will most likely be too complicated for your needs. It's not much work so I will start you off:

    .htaccess:
    <ifModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^(\d+)\.htm$ index.php?id=$1 [NC,L]
    </ifModule>
    Code (markup):
    Then, in index.php
    <?php
    $id = (int) @$_GET['id'];
    if (!$id) {
        // do something when there is no number given
    }
    
    connect to database...
    query database, eg. SELECT ... FROM ... WHERE id = $id
    ?>
    
    PHP:
    From someone who has "I love LAMP" in their avatar, I assume you know a little so if you still need help, just mention what part specifically.
     
    krt, Jun 18, 2007 IP
  5. Lemezo

    Lemezo Active Member

    Messages:
    429
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    75
    #5
    I can code this for you, contact me on
     
    Lemezo, Jun 18, 2007 IP
  6. Joobz

    Joobz Peon

    Messages:
    598
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sweet....

    got it to work with the "id=" just fine. In the mySQL query I wrote it something like this:
    
    <?php
    $result = mysql_query("SELECT recnum, name, age, recdate FROM table WHERE recnum = '$id'");
    if (!$result) {
        echo 'Could not run query: ' . mysql_error();
        exit;
    }
    $row = mysql_fetch_row($result);
    ?>
    Code (markup):
    - I think I got the htaccess part wrong somehow though - I still see the dynamic link. I know I have mod-rewrite enabled with this host.

    also, I'm a little fuzzy on the If statement
    // do something when there is no number given

    what would be an example of a condition for the if statement?

    Thanks!
     
    Joobz, Jun 18, 2007 IP