How to populate webpage content with PHP?

Discussion in 'PHP' started by Sinfullysweet, Sep 3, 2011.

  1. #1
    Good afternoon,

    I am new to learning PHP and MySQL. After 6 hours of nonstop research I have hit a brick wall. I am in the process of designing a website that will need to pull information from mySQL.

    I have a test database set up, and working on the layout. What I am wanting to do is when the webpage loads, if the name of the page is Abjurer.html, I want it to load up the information from my database into the page automatically.

    When doing the php page, instead of actually typing in Abjurers Tunic, I want it to grab the database items that the name of the webpage is.

    $result = mysql_query("SELECT * FROM Cloth
    WHERE Name='Abjurers Tunic'");
    
    
    while($row = mysql_fetch_array($result))
      {
      echo $row['Name'] . " " . $row['Level'];
      echo "<br />";
      }
    ?>
    
    Code (markup):
    But I cannot find anything specific about being able to do that. Is it possible? If so, any help would be appreciated or direction of a tutorial.

    Forgive me for being dumb (since I am sure it is a simple answer) and thank you in advance. (Plus you are helping me with this migrane of hitting a brick wall)
     
    Sinfullysweet, Sep 3, 2011 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    Since it's PHP, the name of the page will be Abjurer.php. You can't run PHP code in an HTML page.

    If you're sending a request from an HTML page to a PHP page (using Javascript), just include the sending page's name in a GET or POST. Then
    
    if(isset($_REQUEST['page']) {
    
      $result = mysql_query("SELECT * FROM Cloth WHERE Name='$page'");
    
      while($row = mysql_fetch_array($result))   {
        echo $row['Name'] . " " . $row['Level'];   echo "<br />";   
      }
    }
    
    Code (markup):
     
    Rukbat, Sep 3, 2011 IP
  3. Sinfullysweet

    Sinfullysweet Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you so much! That tidbit of code got me over my slump. =) It is greatly appreciated!
     
    Sinfullysweet, Sep 3, 2011 IP