|
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
==================
|