PHP/MySQL Question

paul michael king pmking at students.uiuc.edu
Fri Aug 30 14:51:11 EDT 2002


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