Page 1 of 1

displaying database information

Posted: Wed Jun 22, 2005 10:17 am
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.

Posted: Wed Jun 22, 2005 10:37 am
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.