473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

field names in column

Hello, I'm rather new here. I hope this is posted in the right group.
I'm making a database of Dutch wind mills. Those mills contain parts
that give, after clicking, more details. E.g. you can get more
information either about the standing construction or the moving
construction. Now a problem is that I have a lot of fields, but a
query usually gives just a few rows, at most five. So a better
presentation is by turing the rows into columns.
My earlier presentation can be seen from the following code:
<?php
........
$result = (mysql_query($sql, $conn) or die(mysql_error());
echo "<table border = 1>";
echo "<tr alignment = center>";
for($i=0; $i<mysql_num_rows; $i++)
{
echo "<th>".mysql_field_name($result, $i)."</th>";
}
echo "</tr>";
while ($row=mysql_fetch_row($result))
{
echo "<tr align=left>";
for ($i=0; $i<mysql_num_rows(result);$i++)
{
echo "<td>";
if(!isset($row[$i])) //test for NULL
{echo ".";}
else
{echo $row[$i];}
echo "</td>";
}
}
echo "</table>";
?>
I thought it best to make a twodimensional array of the result of my
query. I did it like this.
<?php
$result = (mysql_query($sql, $conn) or die(mysql_error());
settype ($movpart, "array");
for($i=0; $i<mysql_num_rows($result);$i++)
{
for ($j=0; $j<mysql_num_fields($result);$j++)
{
$movpart[$i][mysql_field_name($result,$j)]=
mysql_result($result,$i,mysql_field_name($result,$ j));
}
}
settype ($veld, "array");
for ($v=0; $v<mysql_num_fields($result);$v++)
{
$veld[$v]= mysql_field_name($result,$v);
}

echo "<table>";
for ($v=0; $v<mysql_num_field($result); $v++)
{
echo"<tr alignment=center>";
echo"<th>";
echo $veld[$v];
echo "</th>";
}
echo "</table>";

echo "<table>";
for($k=0; $k<mysql_num_field($result); $k++)
{
echo "<tr align=left>";
for($l=0; $l<mysql_num_rows($result); $l++)
{
echo"<td>";
echo $movpart[$l][$veld[$k]];
echo"</td>";
}
echo"</tr>";
}
echo"</table>";
?>
By placing the last two tables each in a cell of a two-cell table I
get my results. Although the presentation is more or less what I
wanted, it is not very elegant. Has anyone suggestions to a better
solution?
Tanks in advance,
Koos
Jun 27 '08 #1
1 1378
Koos de Vries wrote:
Hello, I'm rather new here. I hope this is posted in the right group.
I'm making a database of Dutch wind mills. Those mills contain parts
that give, after clicking, more details. E.g. you can get more
information either about the standing construction or the moving
construction. Now a problem is that I have a lot of fields, but a
query usually gives just a few rows, at most five. So a better
presentation is by turing the rows into columns.
My earlier presentation can be seen from the following code:
<?php
.......
$result = (mysql_query($sql, $conn) or die(mysql_error());
echo "<table border = 1>";
echo "<tr alignment = center>";
for($i=0; $i<mysql_num_rows; $i++)
{
echo "<th>".mysql_field_name($result, $i)."</th>";
}
echo "</tr>";
while ($row=mysql_fetch_row($result))
{
echo "<tr align=left>";
for ($i=0; $i<mysql_num_rows(result);$i++)
{
echo "<td>";
if(!isset($row[$i])) //test for NULL
{echo ".";}
else
{echo $row[$i];}
echo "</td>";
}
}
echo "</table>";
?>
I thought it best to make a twodimensional array of the result of my
query. I did it like this.
<?php
$result = (mysql_query($sql, $conn) or die(mysql_error());
settype ($movpart, "array");
for($i=0; $i<mysql_num_rows($result);$i++)
{
for ($j=0; $j<mysql_num_fields($result);$j++)
{
$movpart[$i][mysql_field_name($result,$j)]=
mysql_result($result,$i,mysql_field_name($result,$ j));
}
}
settype ($veld, "array");
for ($v=0; $v<mysql_num_fields($result);$v++)
{
$veld[$v]= mysql_field_name($result,$v);
}

echo "<table>";
for ($v=0; $v<mysql_num_field($result); $v++)
{
echo"<tr alignment=center>";
echo"<th>";
echo $veld[$v];
echo "</th>";
}
echo "</table>";

echo "<table>";
for($k=0; $k<mysql_num_field($result); $k++)
{
echo "<tr align=left>";
for($l=0; $l<mysql_num_rows($result); $l++)
{
echo"<td>";
echo $movpart[$l][$veld[$k]];
echo"</td>";
}
echo"</tr>";
}
echo"</table>";
?>
By placing the last two tables each in a cell of a two-cell table I
get my results. Although the presentation is more or less what I
wanted, it is not very elegant. Has anyone suggestions to a better
solution?
Tanks in advance,
Koos
Please don't multipost. Crosspost instead.

Response in alt.php.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Don Leverton | last post by:
Hi Folks, I have been given a CD with approx 130 .xls files (bean-counters!) that I would like to import and merge to ONE table (tblTradeshow). The XL files are *similarly*, but not...
2
by: Ralph | last post by:
I'm trying to import a range of cells from an Excel spreadsheet into a table in access. The first row contains column labels, but I cannot use those as my field names, both because of their format...
5
by: Geoff Portbury | last post by:
I'm a swimming club coach. I have a data base for recording times at various meets. I have a FORM for entering times called SWIM TIMES. When I enter the swimmers name ID, eg FOR01 for Doug Ford I...
3
by: bitoulis | last post by:
Hi, is it possible to use the records of a table as the field names of another table? If yes, how is it done? Thanks in advance Laertes
1
by: Bob | last post by:
When displaying data from the database, very often the field names are not suitable so custom headings have to be created, For example, the column storing zip code may be named zip, but when...
2
by: dhnriverside | last post by:
Hi guys Ok, here's the situation. I'm building a reporting system for my application, that basically creates a CSV file based on a load of data in my database. I'm trying to make the...
3
by: jerry.ranch | last post by:
I'm building my own crosstab table. If a crosstab field has no data in the entire field (as a result of filtering), I don't want to show that field. Is there a way to do this in a qry or frm...
39
by: windandwaves | last post by:
Hi Folk I have to store up to eight boolean bits of information about an item in my database. e.g. with restaurant drive-through facility yellow windows
4
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for...
10
by: Andy B | last post by:
If I have the following text in a dataset table column: "This agreement establishes that {BandName} will play on {EventDate} between {StartTime} and {EndTime}..." How would I then take the field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.