SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2001
    Location
    uk
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help for new person

    All I want to do is display a row from my mysql table in a php page but I don't know the php code , anyone got any idea's.

    thanks

  2. #2
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We will need a bit more information to help you with this, for example are you running the script localhost (on your own pc) or on a server? What is the name of the table, and what kind of information do you want to have pulled out?
    Is it only displaying the data, or do you need help creating the entire search query as well?

    Just give us some more info, and we will see what we can do for you .

  3. #3
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm lets start


    PHP Code:
    //connect to the database

    $connection = mysql_connect("host", "username", "password")
          or die ("Couldn't connect to server");
    $db = mysql_select_db("database", $connection)
        or die ("Couldn't select database.");

    // now we have connected to mysql and selected the database

    /* Now we have to get the row out of the table */

    $sql = "Select * from tablename limit 0,1";
    // this says select all fields from the table but take only the first row

    $result = mysql_query($sql, $connection)
          or die("Couldn't find record.");
    //lets take the result and put it in an array

    $row = mysql_fetch_array($result);
    /*
    now you can echo any field in the database by typing 
    */
    echo "$row[fieldname]";

    // or use it in html by closing php
    ?>
    <HTML>
    <body> 
    <!--- put markup stuff like tables here -->

    <table>
    <tr>
    <td><?= $row["fieldname"]?>
    </td>
    etcetc

    I hope it helps...

    Greets,

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun


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
  •