displaying database information

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

displaying database information

Post by mickd »

Code: Select all

<html> 
<head> 
<link rel=&quote;stylesheet&quote; href=&quote;css.css&quote; type=&quote;text/css&quote;> 
</head> 

<body class=&quote;medium&quote;> 
<?php 
      require 'dbconnect.php'; 
      $username = $_SESSION&#1111;'username']; 
   if(empty($_SESSION&#1111;'username'])) 
      { 
         echo 'An error has occured. It may be that you are not logged in or your session has expired.'; 
      } 
   else 
      { 
      $_SESSION&#1111;'username'] = $username; 
      echo 'Welcome back '; echo $username; 
      echo '<table border=&quote;0&quote;><tr>'; 
      echo '<td width=&quote;200&quote; height=&quote;20&quote; align=&quote;left&quote;>Fav Food:</td>'; 
      echo '<td width=&quote;200&quote; height=&quote;20&quote; align=&quote;right&quote;>'; echo $favfoodhere; 
      echo '</td></tr></table>'; 
      } 
?> 
</body> 
</html>


i havent actually wrote the code yet cos i cant figure out how to do it but heres an example i did.

in the database there is a table called users. inside users there are many fields that have data in it. i was wondering how i would display that users details thats in those fields.

i didnt write out all the tables, one for each field but you get the idea

any help appriciated.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

need to perform a query on the database you do. Loop over the results of the query you must, display the records it will:

ex:

Code: Select all

mysql_connect("localhost","username","password")
  or die(mysql_error());
mysql_select_db("database")
  or die(mysql_error());

$results = mysql_query("select * from users where username = '".mysql_real_escape_string($_SESSION['username'])."'")
  or die(mysql_error());
while($row =  mysql_fetch_assoc($results)){
  echo $row['username']."<br>";
  echo $row['whateverelseisinyourtable'];

}
assumes that does that 'username' is unique on your table.
Post Reply