Retrieve php content from mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RiGGa

    #1

    Retrieve php content from mysql

    Hi,

    I am relatively new to php however I am working on a site and appear to be
    getting on quite well. Most of my pages are coded in php and work fine
    however what I would like to do is be able to retrieve my content from a
    mysql database. The set up is as follows:

    Database contains several fields, but for this example I will only require
    the Page Name and the Content fields. In page name I have the page name
    i.e. whatson.php and I then have the entire contents of the page that I
    worked on in my editor pasted in to the Content field.

    I then create a basic php page that makes a connection to the database and
    just searches for the page I want i.e. whatson.php and stores the result in
    a variable called result.

    I then echo out result but for some reason it just displays the php code and
    does not appear to have interpreted it, can anyone help?. Sample code is
    below:

    <?php


    // Create connection to database
    $db = mysql_connect(" localhost", "username","pas sword") or die("Could not
    connect : " . mysql_error());
    mysql_select_db ("myweb",$db );
    $sql = "SELECT Content FROM pages WHERE PageName = 'whatson.php'" ;
    $sql_result = mysql_query($sq l,$db) or die("Couldn't execute query, please
    notify webmaster.");
    $result = mysql_query($sq l);

    //Main loop below which draws the screen
    while ($row = mysql_fetch_arr ay($sql_result) ) {
    echo $row[0]
    }
    ?>


    I am new to php so be nice :)

    Thanks in advance

    Rigga
  • Michael Fesser

    #2
    Re: Retrieve php content from mysql

    .oO(RiGGa)
    [color=blue]
    >Database contains several fields, but for this example I will only require
    >the Page Name and the Content fields. In page name I have the page name
    >i.e. whatson.php and I then have the entire contents of the page that I
    >worked on in my editor pasted in to the Content field.
    >
    >I then create a basic php page that makes a connection to the database and
    >just searches for the page I want i.e. whatson.php and stores the result in
    >a variable called result.
    >
    >I then echo out result but for some reason it just displays the php code and
    >does not appear to have interpreted it, can anyone help?.[/color]

    You're looking for eval().

    Micha

    Comment

    • RiGGa

      #3
      Re: Retrieve php content from mysql

      Michael Fesser wrote:
      [color=blue]
      > .oO(RiGGa)
      >[color=green]
      >>Database contains several fields, but for this example I will only require
      >>the Page Name and the Content fields. In page name I have the page name
      >>i.e. whatson.php and I then have the entire contents of the page that I
      >>worked on in my editor pasted in to the Content field.
      >>
      >>I then create a basic php page that makes a connection to the database and
      >>just searches for the page I want i.e. whatson.php and stores the result
      >>in a variable called result.
      >>
      >>I then echo out result but for some reason it just displays the php code
      >>and does not appear to have interpreted it, can anyone help?.[/color]
      >
      > You're looking for eval().
      >
      > Micha[/color]
      Thank you, it now works!

      regards

      Comment

      Working...