Page 1 of 1

Column List and Proceeding values

Posted: Fri May 19, 2006 9:14 am
by devain
Hello,


I have a database I am trying to get a column list from along with its proceeding values but for some reason I cannot get it to format right. I have a table entry in my database that consists of one row with id of 1 and multiple columns. These columns and values are not known or change depending on admin usage. The code that I wrote does put the Columns and values but I cannot get it to format right and I cannot get the vairables to be global here is the code that I am working with.
In the HTML below COLUMN Name] is wehre I want the COLUMN name to show up and where COLUMN VALUE the value for each column name.



Appericate any input

Code: Select all

$query = ("select * from table");

$result=mysql_query($query) or die("Query ($query) sucks!");
$fields=mysql_num_fields($result);
$row = mysql_fetch_row($result);
echo "<table>\n<tr>";
for ($i=1; $i < mysql_num_fields($result); $i++) //Table Header
{ 
  
// This prints the Field/ Column names
print "<th>".mysql_field_name($result, $i)."</th>";

	
	 }
echo "</tr>\n";
while ($row = mysql_fetch_row($result)) { //Table body
//echo "<tr>";
   for ($f=1; $f < $fields; $f++) {
   
// This prints the values of each column
echo "$row[$f]";


   
   		

    }
Is there a way to do this to where I can print the column name and then the value that goes with that column without having to do the second loop. I am trying to put this code with the html below.


echo("
<table>
<tr>

<td></td>
<td width=100% valign=top>


<TABLE align=center class=topic style=\"BACKGROUND: #138b9f\" cellSpacing=1 cellPadding=0 width=\"80%\">
<TBODY>
<TR>
<TH style=\"BACKGROUND: #000000; COLOR: #ffffff\"
colSpan=2>COLUMN NAME</TH>
</TR>
<TR>
<TD class=image width=95%>
<span class=\"tRegPriBold\"></span>
<form method=post action=edit_maintemplateinfo.php?edit=COLUMN NAME>
<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" ID=\"Table6\">


<tr>

<td align=\"right\" width=150>COLUMN NAME</td>
<td>
<textarea name=special cols=70 rows=20>COLUMN VALUE</textarea>
</td>
<tr>



<td align=\"right\" width=150></td>
<td>
<hr>
</td>
</tr>

<tr>
<td align=\"right\"></td>
<td>
<input type=\"submit\" value='Update' size=\"20\"/>
</td>
</tr>

</table></table>


</TD></form>
</TR>



</table><br><BR>

");[/b]

Posted: Thu May 25, 2006 9:58 pm
by devain
Thanks for the Help your suggestion did help and I finally figured out how to do it