SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    junkyrddog's Other Half emmester's Avatar
    Join Date
    Mar 2001
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, I would like to introduce myself. I am a 13 yr. old girl who feels alone, for no one her age has such an in-depth interest in web design, etc. So, I have no one to discuss which broswer is better or the dos and don'ts of a design, so I feel this forum will be my escape in a sense. Please excuse any ignorant comments I make, and feel free to blame them on my age. But alas, I must go to the question that has been bugging me...

    I have read a few of the articles at sp.com on databasing, and I am interested in using it on my site. Now, I like the way sp.com looks and I was wondering how they do their pages. As in, if they have a template and retrieve an article from the database, and then format it to the template with whatever code they use. Do they do this or is this even possible?

  2. #2
    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)
    Welcome to the Forums. While your age does not make you stand out - many teenagers visit this site - your sex does and I'm sure yours will be a unique perspective.

    Anyways - yes - very possible - and the way to do it.

    Example my literature site (See link below) I have over 5000 pages of content (www.literature-web.net/sitemap.php3 if you want overload) but I only have oh 6 actual web pages.

    index
    booksearch
    authorsearch
    authorinfo
    book
    view

    Lets just pay attention to the last 3 for now.

    The authorinfo page queries the database and lists information on that author

    so I could do this

    authorinfo.php3/shakespeare

    and get info on the bard

    authorinfo.php3/dickens

    and get info on dickens.

    Thats 2 pages of content - yet 1 actual file.

    Then the book page does the same thing yet for books

    Then the view page displays the actual contents of any book/play/poem. I just pass the unique Id to it like this.

    view.php3/olivertwist/12

    and that would display the 12th chapter of oliver twist. And with about 150 books many with near 100 chapters thats how I get 5000 unique pages of content with only 6 actual files - templates really.


    This is how a typical page may look.

    Code:
    <RETRIEVE VARIABLES FROM URL>
    <DATABASE QUERY>
    <html>
    <head>
    <title><? print("$bookname"); ?></title>
    ...
    ...
    ...
    ...
    <? print("$bookname"); ?> by <? print("$bookauthor"); ?>
    <p>
    <? print("$content"); ?>
    </p>
    </html>
    You see how that works? The best analogy I could think of is an elaborate set of mad libs. You know just fill in the blank. And thats a template.

    Just make your page and figure out what you want to be the same on every page and make that your template - then figure out what you want to change and query the database to get that information.
    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

  3. #3
    junkyrddog's Other Half emmester's Avatar
    Join Date
    Mar 2001
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LOL! Yeah, I suppose me being a girl does stand out a bit, in a peer group where everything is shopping and makeup, I am worried about whether to use Access or Oracle. LOL!

    Wow, though! The amount of content you have is quite impressive, and thank you for posting as well, for your post made me understand this a bit better, and gave me the answer I was praying for. Complete re-designs and site changes are going to extremely easy from now on, and I am excited about what this offers me in relation to my site. Now all I need to do is go lock myself in a dark room, and devour some more articles on scripts and coding for PHP and Databasing. Thanks again!

    + Em

  4. #4
    junkyrddog's Other Half emmester's Avatar
    Join Date
    Mar 2001
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wait, one thing I am confused about is...when you says something.php/dickens--what's going on? What's dickens in reference too? Is dickens the name of one of your databases? And whatev.php/olivertwist/12 is an idea within one of your databases?

    Oh, and does something.php?id=3 do the same thing?
    Last edited by emmester; Mar 8, 2001 at 05:40.

  5. #5
    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)
    Dickens refers to Charles Dickens. The second most famous author of all time ;-)

    and yes...

    you could do this

    book.php3?id=dickens

    but instead I do it like this

    book.php3/dickens

    it's a little more complicated but search engines will index the second value and only google indexes the first value. Basically search engines don't index any URL with a ? or & in it.

    view.php3/olivertwist/12

    passes 2 values to the database. the book oliver twist and chapter 12. it would be the same as

    view.php3?book=olivertwist&chapter=12

    This is code from my view.php3 page
    PHP Code:
    $url_array explode("/",$PATH_INFO); 

    $id=$url_array[1]; 
    $Num=$url_array[2]; 
    // The above gets the path info (/oliver/12) and using the explode function puts it into an array by dividing it along the /'s.  
    //Normally an array would start with arrayname[0] however since there is a preceding / before oliver - oliver is actually the second value in the array (remember computers start at 0, so the second value is 1)

    $db mysql_connect("localhost""username""pw");
    if (!
    $db) {  echo( "<P>Unable to connect to the database server at this time.</P>" );  exit();}

    mysql_select_db("literatu_main"$db);

    $result mysql_query("SELECT * FROM Content WHERE BookID like '$id' AND Chapter_Num='$Num'"$db);
    if (!
    $result) {  echo("<P>Error performing query: " mysql_error() . "</P>");  
    exit();

    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

  6. #6
    junkyrddog's Other Half emmester's Avatar
    Join Date
    Mar 2001
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can happily report that I did know who Dickens was, and that you misunderstood my question. LOL! I meant it to say that if Dickens was the title of a database, with his books being in it.

    Anyways...thank you once, again, you are constantly making things clearer in my eyes.

    it's a little more complicated but search engines will index the second value and only google indexes the first value. Basically search engines don't index any URL with a ? or & in it.

    view.php3/olivertwist/12

    passes 2 values to the database. the book oliver twist and chapter 12. it would be the same as

    view.php3?book=olivertwist&chapter=12
    How come in the first one you didn't have to specify the name of the database (which I am assuming is book) but in the 2nd one you did?

    Also, what programs do you use? Like MySQL, Access, Oracle, etc. and what does it do in general and in regards to you, personally. Thanks!

  7. #7
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    emmester...

    Let me see if I can help here. I am sure that he is using one dbase with multiple tables. A guess at his structure might make it look like this:

    TABLE_BOOK
    name: book name
    authorID: 5
    chapter: contents of chapter 1

    and so on...
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  8. #8
    junkyrddog's Other Half emmester's Avatar
    Join Date
    Mar 2001
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, that's there term. LOL! I keep on referring to tables as different databases...my mistake. But, still, I am interested in how he didn't have to refer to which table he used but rather just the bookid.

  9. #9
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    emmestar,

    aspen uses the table name from which he's getting the info in his sql query.

    SELECT * FROM Content WHERE BookID like '$id' AND Chapter_Num='$Num'
    The sql query selects all the fields (SELECT *) from the Content table (FROM Content).

    Take a look at the following link for more info on using sql:

    http://www.w3schools.com/sql/default.asp

    edit->quote correction
    Last edited by shane; Mar 9, 2001 at 06:32.

  10. #10
    junkyrddog's Other Half emmester's Avatar
    Join Date
    Mar 2001
    Posts
    375
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks shane, I understand now! After looking at the code I was surprised to see how wysiwyg-ish it was. LOL!

    $result = mysql_query("SELECT * FROM Content WHERE BookID like '$id' AND Chapter_Num='$Num'", $db);
    Is that how much is it plainly written out?

  11. #11
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    emmester,

    I think I should say that I use ASP and SQL Sever so I'm not that familiar with PHP and MySql. However, I'll try and help.

    I'm not sure quite what you mean by
    Is that how much is it plainly written out?
    If you mean actually writing the db filed content to the page then I think it would be done something like below. This is assuming that aspen's Content table is something like below.

    Content
    ----------
    BookID
    Chapter_Num
    ChapterContent


    Code:
    $result = mysql_query("SELECT * FROM Content WHERE BookID like '$id' AND Chapter_Num='$Num'", $db);
    if (!$result) {
      echo("<P>Error performing query: " . mysql_error() . "</P>");
    
      exit();
    }
    
    //Get the first row into $row variable
    if ( $row = mysql_fetch_array($result) ) {
      echo("<P>" . $row["ChapterContent"] . "</P>");
    
    }
    If I'm wrong on any of this hopefully one of the PHPers will correct me.

    emmester, have you looked at Kevins article on using PHP and MySQL? It'll give a better help about using php/mysql than I can.

    http://www.webmasterbase.com/article.php?aid=228&pid=0


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
  •