How to echo database fields in php ?

Discussion in 'Programming' started by VisualMaster, Sep 13, 2008.

  1. #1
    So, I'm in need of printing my database data to php page !
    I have a table users, where I've Name, E-Mail fields. When I'm trying to select this table and echo field values - I'm getting white page with no errors :rolleyes:
    What this means ?

    Could you please post some sample of getting data from db and echo'ing them ?
     
    VisualMaster, Sep 13, 2008 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    Test Code

    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("my_db", $con);
    
    $result = mysql_query("SELECT * FROM person");
    
    echo "<table border='1'>
    <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
      echo "<tr>";
      echo "<td>" . $row['FirstName'] . "</td>";
      echo "<td>" . $row['LastName'] . "</td>";
      echo "</tr>";
      }
    echo "</table>";
    
    mysql_close($con);
    ?>
    Code (markup):
    Change it according to your needs
     
    Bohra, Sep 13, 2008 IP
  3. VisualMaster

    VisualMaster Guest

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you very much !
    I tried very similar code but .. this works very well :cool:
     
    VisualMaster, Sep 14, 2008 IP