Thank you for your efforts. The ideas are helping but sorry I am not
clear.  Not used to expressing myself regarding the coding I do. 

What I am looking to do is this:

>From a loop that is reading a list of titles, I want to input pieces
of information to each...  The input fields will be in a  column on a
form with the name of the array at the top.

In a loop to n:
print "<INPUT TYPE='text' NAME='fred[]' SIZE='10' MAXLENGTH='10'> ";

Fred works fine hard coded but i get n fred's...  I need the
individual  array names to be whatever comes from the list, column by
column.

Maybe this is very simple but I am not seeing how it's done.

Floyd





On Sat, 23 Nov 2002 15:28:13 -0800, you wrote:

>Floyd,
>if you are using mysql then you can use the mysql_list_fields to get the
>names of the mysql table's column (field) names, then do mysql_num_fields to
>get the number of columns (fields), then fill the columns with whatever
>using a while loop.
>I've attached a php page that fetches this info from any size table then
>displays the table.  You can extract the info you need and extend it with
>check boxes etc.
>Hope this helps.
>Hugh
>
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
><html>
><head>
><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
><title>Input Data Page</title>
><?php include ("css.txt"); ?>
></head>
><body bgcolor="#1D3E81" >
><h1><font color="#ffff33">DATABASE TABLES</font></h1>
>
><form action="<?php print $php_self?>" method="post">
><?php
>
>print "<table cellpadding=7 border=1 bgcolor=#d5d5d5><tr><td>";
>print "<h6>Database name:</h6><input type=text name=db
>STYLE=width:140px></td><td>";
>print "<h6>Username:</h6><input type=text name=user STYLE=width:140px>";
>print "<h6>Password:</h6><input type=text name=pass STYLE=width:140px>";
>print "</td><td valign=middle align=center><input type=submit value=\" go
>\">";
>print "<input type=hidden name=start value=1>";
>print "</td></tr></table></form><br>";
>if ($start=="1")
> {
> $link=mysql_connect("localhost","$user","$pass");
> if (! $link) die("couldn't connect mysql");
> mysql_select_db($db,$link) or die ("couldn't open $db ".mysql_error());
> $tables=mysql_list_tables($db,$link);
> $num=mysql_num_rows($tables)-1;
> mysql_close($link);
> ?>
> <form action="<?php print $php_self?>" method="post">
> <?php
> print "<table cellpadding=7 border=1 bgcolor=#d5d5d5><tr><td>";
> print "<h6>Table Name: </h6><select type=text name=table
>STYLE=width:140px><option>";
>
> for ($i=0;$i<=$num;$i++)
>  {
>  print "<option>".mysql_tablename($tables,$i);
>  }
> print "</select>";
>
> print "</td><td><input type=submit value=\" go  \">";
> print "<input type=hidden name=start value=2>";
>
> print "<input type=hidden name=db value=$db>";
> print "<input type=hidden name=user value=$user>";
> print "<input type=hidden name=pass value=$pass>";
> print "</td></tr></table></form><br>";
> }
>
>if ($start=="2")
> {
> $link=mysql_connect("localhost","$user","$pass");
> if (! $link) die("couldn't connect mysql");
> mysql_select_db($db,$link) or die ("couldn't open $db ".mysql_error());
>
> $results=mysql_query("select * from $table");
> $fields = mysql_list_fields("$db", "$table", $link);
> $columns = mysql_num_fields($fields);
> mysql_close($link);
> print "<table width=95% bgcolor=#d5d5d5 border=1 cellspacing=0
>cellpadding=0><tr><td align=center><h3>$table</h3>";
> print "<table width=100% bgcolor=#d5d5d5 border=1 cellspacing=0
>cellpadding=4>";
> print "<tr>";
> for ($i = 0; $i < $columns; $i++)
>  {
>  print "<td align=center bgcolor=#6c6c6c><h5><font
>color=white>".mysql_field_name($fields, $i)."</font></h5></td>";
>  }
> print "</tr>";
> print "<tr>";
> for ($i = 0; $i < $columns; $i++)
>  {
>  print "<td align=center bgcolor=#fbfbfb><h5>".mysql_field_type($results,
>$i)."</h5></td>";
>  }
> print "</tr>";
> while ($a_row=mysql_fetch_row($results))
>  {
>  print "<tr>";
>  foreach($a_row as $field)
>   {
>   if ($field=="")
>    {
>    $field="&nbsp;";
>    }
>   print "<td align=center><h5>".$field."</h5></td>";
>   }
>  print "</tr>";
>  }
> print "</table></td></tr></table>";
> }
>?>
></body>
></html>
>
>
>
>----- Original Message -----
>From: "Floyd Baker" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Cc: <[EMAIL PROTECTED]>
>Sent: Saturday, November 23, 2002 2:07 PM
>Subject: Re: [PHP] dynamic arraynames
>
>
>> On Sat, 23 Nov 2002 10:58:02 -0500, you wrote:
>>
>> >> I am trying to generate arrays to hold inputs to columns.  Column
>> >> titles are input to a table as needed.  They are read by the program
>> >> and placed across the page.  Then an array goes under each column name
>> >> to collect the inputs to the various rows.  Everything works except to
>> >> dynamically change the name of the array.
>> >>
>> >>
>> >> while($foo=mysql_fetch_array($mysql_result)){
>> >>     print "<INPUT TYPE=text NAME=correspondingfoo[]>";}
>> >
>> >Do you want this??
>> >
>> >print "<INPUT TYPE=text NAME=" . $foo['something'] . "[]>";
>> >
>> >---John Holmes...
>>
>>
>> No John.  I'm ok with simply inputting a value and otherwise using
>> arrays that are hard coded and previously named but my problem is in
>> creating different arrays on the fly to represent each column that
>> there is a name for.  I want to end up with something like $meat[] and
>> $potatoes[] and whatever else is needed from a list...  The list of
>> meat, potatoes, etc determines how many arrays and their names.
>>
>> I'm not to swift when it comes to arrays and think I'm probably stuck
>> on some simple misconception.  I'm trying to convert $meat to $meat[],
>> on the fly, to have something to input to...  I read today maybe I
>> don't need the brackets?
>>
>> Floyd
>>
>>
>> --
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>

--


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to