How to render webpages based on database rows

Discussion in 'Programming' started by michiganfootball20, Oct 11, 2010.

  1. #1
    Alright so I have a website which displays a bunch of different rows from a database on a single page, but I want to expand the site so each individual row has its own page where more in depth information on the record can be found..

    The sites database is mysql btw... Im decent enough at coding to figure it out if someone can give me a basic breakdown or refer me to somewhere where the matter is discussed more..

    Thanks.
    MF20
     
    michiganfootball20, Oct 11, 2010 IP
  2. SamT

    SamT Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    (Mainly geared towards PHP)

    First set up your procedure:
    - Take input (i.e, some parameter, page.php?page=??? )
    - look up in database table
    - Output table content

    
    <?php
    
    $page = $_GET['page'];
    
    $db = mysql_connect('localhost', 'db_username', 'myPa$$word');
    mysql_select_db('datbase-name');
    
    $page = mysql_real_escape_string($page);
    $sql = "SELECT * FROM pages WHERE url = '$page' ";
    $result = mysql_query($sql);
    $row = mysql_fetch_assc($result);
    
    echo "<html><head><title>{$row['title']}</title></head><body>{$row['body']}</body></html>";
    
    
    Code (markup):
    The table (called 'pages') has 3 columns:
    url varchar(40)
    title varchar(255)
    body text

    http://php.net/manual/en/book.mysql.php
    Some of my code I wrote may have some syntax errors or spelling issues with the function names, verify they are correct in that manual page.
     
    Last edited: Oct 12, 2010
    SamT, Oct 12, 2010 IP
  3. michiganfootball20

    michiganfootball20 Peon

    Messages:
    536
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks.. yeah i know how to do that.. for some reason i was thinking it would be a lot more complex. do you by any chance know how well pages like that (which include characters like question marks) do in the search engines?
     
    michiganfootball20, Oct 20, 2010 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You should be using URL rewriting rather than having an actual parameter to optimise it for SEO but other than that the fact that they are being generated from an SQL on the fly rather than being static HTML will have no impact (other than the very rare unfortunate cases when google bot tries to spider whilst theres a sql connection error etc)
     
    AstarothSolutions, Oct 21, 2010 IP
  5. papillon

    papillon Greenhorn

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    always URL rewrite for SEO
     
    papillon, Oct 22, 2010 IP