View Single Post
Join Date: Jan 2008
Posts: 100
Reputation: rickarro is an unknown quantity at this point 
Solved Threads: 1
rickarro rickarro is offline Offline
Junior Poster

php query headers

 
0
  #1
May 6th, 2008
Hey All,

I have a simple query form that displays from a mysql database, a list of names and phone numbers. What i'd like is a column heading at the top of the page but I can't seem to figure out how to put it in there. Here is my code so far:
  1. <?php
  2.  
  3. // set database server access variables:
  4. $host = "localhost";
  5. $user = "user";
  6. $pass = "password";
  7. $db = "phonebook";
  8.  
  9. $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
  10.  
  11. mysql_select_db($db) or die ("Unable to select database!");
  12.  
  13. $query = "SELECT * FROM people ORDER BY fname ASC";
  14.  
  15. // execute query
  16. $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
  17.  
  18. // see if any rows were returned
  19. if (mysql_num_rows($result) > 0) {
  20. // yes
  21. // print them one after another
  22. echo "<table cellpadding=10 border=0>";
  23. while($row = mysql_fetch_row($result)) {
  24. echo "<tr>";
  25. echo "<td>".$row[1]."</td>";
  26. echo "<td>".$row[2]."</td>";
  27. echo "<td>".$row[3]."</td>";
  28. echo "<td>".$row[4]."</td>";
  29. echo "<td>".$row[5]."</td>";
  30. echo "<td>".$row[6]."</td>";
  31. echo "<td>".$row[7]."</td>";
  32. echo "</tr>";
  33. }
  34. echo "</table>";
  35. }
  36. else {
  37. // no
  38. // print status message
  39. echo "No rows found!";
  40. }
  41.  
  42. // free result set memory
  43. mysql_free_result($result);
  44.  
  45. // close connection
  46. mysql_close($connection);
  47.  
  48. ?>
I don't want to use the actual table names because they are abbreviated, ie fname = First Name. But I do want to let the viewer know what each of the columns are. How can I do this.

Thanks.
Reply With Quote