Click here to get back home

field names in column

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
field names in column Koos de Vries 06-11-2008
Posted by Koos de Vries on June 11, 2008, 1:56 pm
Please log in for more thread options
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

Posted by Jerry Stuckle on June 11, 2008, 2:11 pm
Please log in for more thread options
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.
jstucklex@attglobal.net
==================


Similar ThreadsPosted
numeric column names in mysql? March 12, 2006, 8:57 pm
Write custom column names to query result file May 3, 2005, 12:42 pm
pdo get field names December 12, 2005, 11:49 pm
Unknown column 'icaodesc' in 'field list' August 12, 2005, 4:58 pm
Capturing HTML form field names even when they are blank February 7, 2005, 3:50 pm
Storing form field names in an array and writing values to a text file July 15, 2004, 6:36 pm
Can a field communicate to a server and return information to another field without retrieving the whole html code again? January 13, 2005, 10:27 am
How do you specify a field in a table join that has the same name as another field? August 7, 2007, 10:08 am
Get the name of the column October 30, 2007, 2:55 pm
Get the name of the column 2 October 30, 2007, 6:54 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap