How to display data in a PHP variable at a HTML page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Udara chathuranga
    New Member
    • Aug 2010
    • 14

    How to display data in a PHP variable at a HTML page?

    I have created a php page to retrieve data from a database. Now I want to display the data that I retried at a HTML page. How I can do that?
  • Thew
    New Member
    • Aug 2010
    • 69

    #2
    Code:
    echo $data;

    Comment

    • AutumnsDecay
      New Member
      • Mar 2008
      • 170

      #3
      It depends on how you want to show your data.

      Let's assume we have a database called 'users', and we want to pull and show ALL the data in that table. The 'users' table has 3 columns:

      1) id
      2) username
      3) email

      Our query would look like:

      Code:
      $query = "SELECT * FROM users ORDER BY id ASC";
      Now, because we potentially have a long list of information, we can just spit it out on the screen, as that would be nearly impossible to sort through. So, we perform a 'while loop' to keep our data sort.

      Code:
      $result = mysql_query($query);
      while ($row = mysql_fetch_assoc($result)){
          print 'Id: ' . $row['id'] . '<br />';
          print 'Username: ' . $row['username'] . '<br />';
          print 'Email: ' . $row['email'] . '<br />';
          print 'END OF CURRENT USER INFORMATION <br /><br />';
      }
      Here's what that would look like:

      Id: 1
      Username: jappleseed
      Email: jappleseed25@ho tmail.com
      END OF CURRENT USER INFORMATION

      Id: 2
      Username: HonestAbe
      Email: alincoln@gmail. com
      END OF CURRENT USER INFORMATION

      etc.

      Comment

      • Udara chathuranga
        New Member
        • Aug 2010
        • 14

        #4
        The codes you are given above is in a .php file. And we get the final out put in a .php file. But I need to know is how to transfer those outputs in to a .html file.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          is it necessary to put it in an .html file? if the .php file has the correct content, it is no different from a .html file.

          Comment

          • Udara chathuranga
            New Member
            • Aug 2010
            • 14

            #6
            OK I understood it is not possible to do that. Thanks

            Comment

            Working...