[WEB4LIB] PHP/MySQL Question

Peter.Binkley at ualberta.ca Peter.Binkley at ualberta.ca
Fri Aug 30 17:29:37 EDT 2002


There's nothing forcing you to display the column names returned by MySQL.
Why not use an array: 

$columns = array( 
'phone_1' => 'Office Phone', 
'phone_2' => 'Home Phone', 
...
); 

Then display "$columns[mysql_field_name($result,$i)]" in each case.

Peter

Peter Binkley
Digital Initiatives Technology Librarian
email: peter.binkley at ualberta.ca
phone: (780) 492-3743
fax: (780) 492-9243
post: Cameron Library 4-30
      University of Alberta
      Edmonton Alberta 
      Canada T6G 2J8

> -----Original Message-----
> From: paul michael king [mailto:pmking at students.uiuc.edu] 
> Sent: Friday, August 30, 2002 12:52 PM
> To: Multiple recipients of list
> Subject: [WEB4LIB] PHP/MySQL Question
> 
> 
> Hello Everyone,
> 
> I am currently constructing a website that uses php to 
> interface with MySQL database to retrieve information and 
> format it into tables.  I am new to programming, though, and 
> have had some minor trouble.
> 
> It is recommended in MySQL documentation that column names be 
> one word. I have therefore named my columns using unsightly 
> programming syntax such as 'phone_1', 'phone_2', etc. Does 
> anyone know how I can rename and reformat the column headers 
> for the final HTML table? My guess is that regular 
> expressions would be involved. I have included the relevant 
> piece of code below, so that you know how I am doing what 
> I've done so far. If anyone would like to see the actual 
> webpage, let me know. I am a bit reticent to post it, though, 
> because the information in the database is considered sensitive.
> 
> <?php
> 
> print("<TR BGCOLOR=\"#CCCCCC\" ALIGN=\"center\" VALIGN=\"middle\">");
> for($i=0;$i<mysql_num_fields($result);$i++) {
> 	print("<TD VALIGN=\"center\" ALIGN=\"center\"><B>");
> 	echo mysql_field_name($result,$i);
> 	print("</B></TD>");
> 	}
> 
> print("\n</TR><TR></TR><TR></TR>\n");
> 
> while($row=mysql_fetch_row($result)) {
> 	print("<TR BGCOLOR=\"#FFCCFF\" VALIGN=\"baseline\">\n");
> 	for($i=0;$i<mysql_num_fields($result);$i++) {
> 		print("<TD VALIGN=\"center\" ALIGN=\"left\">");
> 		echo $row[$i];
> 		print("</TD>");
> 		}
> 	print("\n</TR>\n");
> }
> 
> mysql_close($link);
> ?>
> 
> Thank you for any and all help! I appreciate it!!
> 
> --paul king,
> LIS Grad Student
> University of Illinois
> 
> 
> 



More information about the Web4lib mailing list