SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search Engine-Friendly URLs

    Hi, I created a database news engine at this url: http://www.nintendofire.com/nfnews

    all the news articles come out like this:
    /nfnews/news.php?id=17
    and I want them like this:
    /nfnews/news.php/17

    So far, very simple. Now I want to make it search engine-friendly like in this article: http://www.promotionbase.com/article.php?aid=485&pid=0

    This particular set of coding is giving me a hard time.
    PHP Code:
    $var_array explode("/",$PATH_INFO);

    $var_array[0] = "article.php"

    $var_array[1] = 999

    $var_array
    [2] = 12 
    Here are a few details. The id is $id and my version of "article.php" would be "news.php". It will explode {http://www.nintendofire.com/nfnews/news.php/18} the url, but won't get anything from the database below this line:

    PHP Code:
    while ($row mysql_fetch_array
       
    ($result)) {


    print(
    "<h3 align=\"center\">$row[Title]</h3>");
    print(
    "<p>Reported by <a href=\"mailto:$row[Email]\">$row[Author]</a> on $row[Date]");
    print(
    "<p>Category: $row[Cat]");
    print(
    "<p>$row[FullNews]");
    print(
    "<p><font size=1>Related Link: <a href=$row[Link]>$row[Link]</a></font>"); 
    But I can't figure out what to add for the variables. Has anyone done this? Some help would be great, thanks
    Last edited by PlayOn; Mar 26, 2002 at 10:28.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the entire script for news.php
    PHP Code:
    <? header("HTTP/1.1 200 OK"); ?>
    <html>
    <head>
    <title>Getting info from the Database</title></head>
    <body>
    <style>
    <!--
    th,td {font-family:verdana;font-size:12px}
    A:link {color:#000000;font-family:verdana;font-size:12px}
    A:visited {color:#000000;font-family:verdana;font-size:12px}
    A:active {color:#000000;font-family:verdana;font-size:12px}
    h3 {font-family:verdana}
    -->
    </style>
    <?

    $var_array 
    explode("/",$PATH_INFO);

    $var_array[0] = "news.php";

    $var_array[1] = "$news.php";

    $var_array[2] = "$id";


    $host "localhost";
    $user "xxx"
    $password "xxxx";
    $database "xxxx";
    $tablename="news";

    $link mysql_connect ($host$user$password);

    $query "SELECT * from $tablename where (id='$id')";

    $result mysql_db_query ($database$query$link);

    print(
    "<table width=500 bgcolor=#000000 cellpadding=3 cellspacing=1><tr><td bgcolor=#ff9933>");
    print(
    "<h3 align=\"center\">$row[Title]</h3>");

    while (
    $row mysql_fetch_array
       
    ($result)) {


    print(
    "<h3 align=\"center\">$row[Title]</h3>");
    print(
    "<p>Reported by <a href=\"mailto:$row[Email]\">$row[Author]</a> on $row[Date]");
    print(
    "<p>Category: $row[Cat]");
    print(
    "<p>$row[FullNews]");
    print(
    "<p><font size=1>Related Link: <a href=$row[Link]>$row[Link]</a></font>");


    }
    mysql_close ($link);
    print(
    "</td></tr></table><p><p><font size=2 face=verdana><a href=index.php>Return to Main Page</a>");
    ?>
    </body>
    </html>
    Last edited by aspen; Mar 26, 2002 at 22:43.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't there anyone who can help on this????

  4. #4
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Send a PM to aspen -- he is the guy who wrote the article and probably the best person to help you!
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  5. #5
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, thanks a lot. I appreciate it!

  6. #6
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay here is the problem.

    In the article I wrote:

    $var_array = explode("/",$PATH_INFO);

    $var_array[0] = "article.php"

    $var_array[1] = 999

    $var_array[2] = 12
    To illustrate the values the variables were assigned in the explode function. Really what I was trying to say was this:

    PHP Code:
    $var_array explode("/",$PATH_INFO);

    echo 
    $var_array[0// "article.php"

    echo $var_array[1// 999

    echo $var_array[2// 12 
    So what you need to do is this:

    PHP Code:
    $var_array explode("/",$PATH_INFO);

    $id $var_array[1]; 
    Then you can use the $id variable to query your database. Technically you could also use $var_array[1] to query your database, renaming it is purely for ease of code reading.

    Note I am using var_array[1], not var_array[2], as ID because in your setup:

    news.php/17

    var_array[0] would equal news.php and var_array[1] would equal 17, and there isn't a var_array[2].

    You are currently using method 1 from my article, I would suggest using method 3 instead - its the same principle but by adding a few lines to your .htaccess file you make the URLs even more search engine friendly.



    ps, I've edited your post, but in the future you should refrain from posting your database userid and password in the forums - thats a pretty big security risk.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  7. #7
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also this line:

    <? header("HTTP/1.1 200 OK"); ?>

    Is only needed if you're using method 2 (custom error pages) from my article, methods 1 or 3 do not require it.

    Also in the future you should post a more meaningful thread title (like Help with search engine friendly urls) or something. "PHP coding help" doesn't really tell anyone what the thread is about.
    Last edited by aspen; Mar 26, 2002 at 22:58.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  8. #8
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by aspen
    I've edited your post, but in the future you should refrain from posting your database userid and password in the forums - thats a pretty big security risk.
    i just wanted to say that i don't really care if anybody sees my MySQL username and password. it doesn't matter for most people, since only localhost connections are allowed. besides, others on my [virtual] server, who COULD connect to my database, can get the info from my config file.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  9. #9
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks a lot Chris, I totally understand this now. Probably should have left my username/password out but it's only a test DB. Again, thanks!

    PS- I did add a ForceType directive btw, news?id=17 works on my server, so news will come out as /news/17. My next step is to implement another array in there for the date.

    /news/6-24-2002/1752 -Like that.
    Last edited by PlayOn; Mar 27, 2002 at 10:19.

  10. #10
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by aspen
    [BAlso in the future you should post a more meaningful thread title (like Help with search engine friendly urls) or something. "PHP coding help" doesn't really tell anyone what the thread is about. [/B]
    Yah I realized that and tried to rename my post but it would not let me.


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
  •