473,395 Members | 2,468 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,395 software developers and data experts.

Using numbers for html form field array names - is this too strange?

Currently I have a number of html forms which loop through records in
a database table. In order to be able to update the right record when
the form is submitted, I've tacked number on to the field names, i.e.:

PHP: echo '<input type="text" name="hat_color_'.$i.'"
value="'.$currentRow['hat_color'].'">
<input type="text" name="favorite_food_'.$i.'"
value="'.$currentRow['favorite_food'].'">';

HTML: <input type="text" name="hat_color_0" value="brown"><input
type="text" name="favorite_food_0" value="pizza">
<input type="text" name="hat_color_1" value="black"><input type="text"
name="favorite_food_1" value="fries">
....
After submit, $_POST['hat_color_0'] = 'brown'
$_POST['hat_color_1'] = 'black'
$_POST['favorite_food_0'] = 'pizza'
$_POST['favorite_food_1'] = 'fries'
....

In the past I have also done this with arrays, i.e.:

PHP: echo '<input type="text" name="hat_color[]"
value="'.$currentRow['hat_color'].'">';
HTML: <input type="text" name="hat_color[]" value="brown">
<input type="text" name="hat_color[]" value="black">
....
After submit, $_POST['hat_color'][0] = 'brown'
$_POST['hat_color'][1] = 'black'
....
Now, here's my crazy idea... Since it's really easy to get my query
results into an array in the form of
$result_array[$rownumber][$fieldname], would I run into any problems
naming my form fields like this:

HTML: <input type="text" name="0[hat_color]" value="brown">
<input type="text" name="0[favorite_food]" value="pizza">
<input type="text" name="1[hat_color]" value="brown">
<input type="text" name="1[favorite_food]" value="pizza">
....
After submit, $_POST[0]['hat_color'] = 'brown'
$_POST[0]['favorite_food'] = 'pizza'
$_POST[1]['hat_color'] = 'black'
$_POST[1]['favorite_food'] = 'fries'
....
I know that it's fairly easy to switch back and forth... It just
struck me as a way to keep all my arrays in the same form whether I'm
getting data from the database, an html form, or whatever. Using
name="123[yadda_yadda]" strikes me as odd, but it seems to work.
Anyone got a good reason not to do this?
Jul 17 '05 #1
0 9878

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

Similar topics

0
by: Phil Powell | last post by:
I traced the problem to what I believe is when I use the included content library script into the viewinterns.php page. This script will repeatedly instantiate a DateGroupHTMLGenerator class...
9
by: Randell D. | last post by:
Folks, I can program fairly comfortably in PHP and can, for the most part using these skills and others that I've picked up over the years manage to read/understand most code in Javascript... so...
10
by: Chamomile | last post by:
I have been happily using array members as id's in my html code (either hand coded or generated by server-side script-php ) for some time. eg < input type='text' id='arrayItem' >< input...
5
by: Steve Wylie | last post by:
I am constructing an HTML questionnaire and one of the questions requires people to rate some choices from 1 to 5, where 1 is their favourite and 5 is their least favourite: Car Bus Taxi cab...
19
by: becte | last post by:
I need to use three bytes to store four 6-bit integers (4 * 6 = 3 * 8) like this 11111122|22223333|33444444 Suppose the input is, int c1, c2, c3, c4, range 0 .. 2^6 -1 and the output is int...
1
by: Suhail A, Salman | last post by:
Dear All, I placed a HtmlSelect control on a web page and set it to "Run at Server", the objective of this HtmlSelect control is that the client adds all his accounts to a text box, and...
13
by: Kantha | last post by:
Hi all, I have declared an Union as follows typedef union { struct interrupt_bits { unsigned char c_int_hs_fs_status : 1, c_setup_intflag : 1,
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.