Re: looping through fields in a table
| From: | Ray Black III | Date: | Tue, 30 May 2000 15:14:31 +0000 |
| Subject: | Re: looping through fields in a table | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-642@lists.php.net to get a copy of this message | ||
I dealt with this problem just this past week, and yes it's possible to do
this however you'd like. The basic premise of getting field names and their
corresponding values is a simple one, though:
$fields = $field_values = "";
for ($i=1; list($key, $val) = each($arr); $i++ )
{
$fields .= $key;
$field_values .= "'". $val ."'";
if ($i < sizeof($arr)):
$fields .= ", ";
$field_values .= ", ";
endif;
}
This gives you comma-delineated strings of Fields and Field Values from a
1-D associative array, which is what I needed for a silly little database
insert... you can modify it as it suits you.
-r3-
----- Original Message -----
From: Sam Masiello <smasiello@chekinc.com>
To: <M.vanderMerwe@expro.shell.co.uk>; <php-general@lists.php.net>
Sent: Tuesday, May 30, 2000 11:02 AM
Subject: RE: [PHP-GENERAL] looping through fields in a table
>
> This partly depends on how you want to present the information. It could
be
> done in a couple of different ways depending on whether you want to
present
> your data with column headers along the top (in a tabular fashion) or
along
> the side like this:
>
> Field1:Value1
> Field2: Value2
> Field3: Value3
>
> Field1: Value1
> <etc etc>
>
> In either case, the short answer to your question is yes, this is
possible.
> I do not know of a way that you can get the field NAMES, however without
> hard coding that information as part of your data presentation. So, if
you
> are looking for a dynamic way to to do this (in the case where you add
> additional fields to your table), I am not sure if that is possible.
>
> Sam Masiello
> System Analyst
> Chek.Com
> (716) 853-1362 x289
> smasiello@chekinc.com
>
> -----Original Message-----
> From: M.vanderMerwe@expro.shell.co.uk
> [mailto:M.vanderMerwe@expro.shell.co.uk]
> Sent: Tuesday, May 30, 2000 10:58 AM
> To: php-general@lists.php.net
> Subject: [PHP-GENERAL] looping through fields in a table
>
> << File: BDY.TXT >> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net