473,396 Members | 1,853 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,396 software developers and data experts.

Getting a (non-radio) button's index number from array

Hello,
If you could assist me with the following situation, I would be very
grateful.

I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";

In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";
}
Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?

Thank you, once again, for any assistance that you can provide,
Simon Gottesman

Apr 19 '07 #1
6 2702
On Apr 19, 2:13 am, sgotte...@yahoo.com wrote:
Hello,
If you could assist me with the following situation, I would be very
grateful.

I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";

In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";}

Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?

Thank you, once again, for any assistance that you can provide,
Simon Gottesman
although this approach could work, it might not work as you intend if
the database has changed since the rows were received. your comment
could be associated with the wrong row in the db.
Perhaps what you need is an ID for each row, so that you can associate
the button with that id, create a column and populate it with a unique
ID, you /could/ use an auto_increment column, but will probably find
it easier in the long run if you don't and simply adjust your table
and populate it manually when updating and altering the table.
the job of creating unique names for your inputs is now easy.

watch how much data you retunr though, creating buttons for each
(possibly unused) row means more in the DOM (more in memory) and more
clutter on the page.
Consider using javascript to add to the DOM only what the user wishes
to edit, adding a small form with the 3 or so buttons, which appear
below the row when the user clicks, if you add an iframe too pointing
towards the update script, you have an AJAX style synamic updater
which can be used repeatedly on the same page to update many rows with
no need for a refresh with its database querying overhead. Once again
thoughm if the rows can be edited by more than one user at a time,
make sure the logic checks for changes before overwriting. To do this
you could populate a session serverside with the results from the
database, and check that the values from the session are still the
same as the values from the database, before updating. I know its a
hassle, but will avoid too many users upsetting each other, the good
news is that when a user changes the database while another user is
attempting to do it, you can notify the other user without them
leaving the page, of the new value, and ask whether they wish to still
carry on. Just ignore all this if its never likely to grow to the
point where you care about this. Its just that since you are returning
a lot of data (by the sound of it) it suggested to me that the data
counld be presented to multiple users at once if multple users are
using that part of the app. and although the chances of each user
updating the same row could be seen to be small compared to the set
size, the context is what will drive the need to update, rather than
the simple probability, and so it could be a problem. rabbit rabbit,
perhaps i need sleep!

Apr 19 '07 #2
sg*******@yahoo.com wrote:
Hello,
If you could assist me with the following situation, I would be very
grateful.

I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";

In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";
}
Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?

Thank you, once again, for any assistance that you can provide,
Simon Gottesman
Simon,

Since you can only press one button to submit your form, you will only
get one button back - and it's index will always be zero. In the case
of a submit button, the brackets in 'name="Comment[]"' are superfluous -
you can't get back more than one button.

What you want is to get the id of the row (you do have a unique ID for
each row, right?) and use it in your name, i.e.

" ... name=\"comment[$id]\" ... "

Now you can get the $_POST['comment'] array and check your key to get
the id of the row.

No javascript or DOM needed.

Of course, there are other ways, but I like this one.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 19 '07 #3
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
sgotte...@yahoo.com wrote:
Hello,
If you could assist me with the following situation, I would be very
grateful.
I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";
In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";
}
Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?
Thank you, once again, for any assistance that you can provide,
Simon Gottesman

Simon,

Since you can only press one button to submit your form, you will only
get one button back - and it's index will always be zero. In the case
of a submit button, the brackets in 'name="Comment[]"' are superfluous -
you can't get back more than one button.

What you want is to get the id of the row (you do have a unique ID for
each row, right?) and use it in your name, i.e.

" ... name=\"comment[$id]\" ... "

Now you can get the $_POST['comment'] array and check your key to get
the id of the row.

No javascript or DOM needed.

Of course, there are other ways, but I like this one.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
i suppose it could be added that the [] technique /can/ be very useful
if you are making many comments at once, which is what I assumed.
another eg. When you are /submitting/ a lot of inputs each with unique
values which taken together mean something, for instance a series of
ordered triples, like 3D coordinates.
As Jerry points out, you don't need js if you print out the full DOM
in markup, you are advised to use paging with a LIMIT BY clause in
your sql, to ensure things don't grow unmanageably as the data in the
table grows.

Apr 19 '07 #4
shimmyshack wrote:
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
>sgotte...@yahoo.com wrote:
>>Hello,
If you could assist me with the following situation, I would be very
grateful.
I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";
In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";
}
Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?
Thank you, once again, for any assistance that you can provide,
Simon Gottesman
Simon,

Since you can only press one button to submit your form, you will only
get one button back - and it's index will always be zero. In the case
of a submit button, the brackets in 'name="Comment[]"' are superfluous -
you can't get back more than one button.

What you want is to get the id of the row (you do have a unique ID for
each row, right?) and use it in your name, i.e.

" ... name=\"comment[$id]\" ... "

Now you can get the $_POST['comment'] array and check your key to get
the id of the row.

No javascript or DOM needed.

Of course, there are other ways, but I like this one.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

i suppose it could be added that the [] technique /can/ be very useful
if you are making many comments at once, which is what I assumed.
another eg. When you are /submitting/ a lot of inputs each with unique
values which taken together mean something, for instance a series of
ordered triples, like 3D coordinates.
As Jerry points out, you don't need js if you print out the full DOM
in markup, you are advised to use paging with a LIMIT BY clause in
your sql, to ensure things don't grow unmanageably as the data in the
table grows.
He doesn't need the full DOM at all. Just use the row id as the index
to the array.

There needs to be some unique way to identify the row in the database.
Otherwise you can get the wrong row, i.e. if the database has changed as
you noted.

Whether it's an autoincrement or other type of column, that identifier
can be used as the index to the array. Then it's easy to retrieve the
correct row all the time.

And I agree - he needs to limit the amount of data returned now, not later.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 19 '07 #5
On Apr 19, 9:57 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
shimmyshack wrote:
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
sgotte...@yahoo.com wrote:
Hello,
If you could assist me with the following situation, I would be very
grateful.
I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";
In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";
}
Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?
Thank you, once again, for any assistance that you can provide,
Simon Gottesman
Simon,
Since you can only press one button to submit your form, you will only
get one button back - and it's index will always be zero. In the case
of a submit button, the brackets in 'name="Comment[]"' are superfluous -
you can't get back more than one button.
What you want is to get the id of the row (you do have a unique ID for
each row, right?) and use it in your name, i.e.
" ... name=\"comment[$id]\" ... "
Now you can get the $_POST['comment'] array and check your key to get
the id of the row.
No javascript or DOM needed.
Of course, there are other ways, but I like this one.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
i suppose it could be added that the [] technique /can/ be very useful
if you are making many comments at once, which is what I assumed.
another eg. When you are /submitting/ a lot of inputs each with unique
values which taken together mean something, for instance a series of
ordered triples, like 3D coordinates.
As Jerry points out, you don't need js if you print out the full DOM
in markup, you are advised to use paging with a LIMIT BY clause in
your sql, to ensure things don't grow unmanageably as the data in the
table grows.

He doesn't need the full DOM at all. Just use the row id as the index
to the array.

There needs to be some unique way to identify the row in the database.
Otherwise you can get the wrong row, i.e. if the database has changed as
you noted.

Whether it's an autoincrement or other type of column, that identifier
can be used as the index to the array. Then it's easy to retrieve the
correct row all the time.

And I agree - he needs to limit the amount of data returned now, not later.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
Thank you both for your replies.
I will try Jerry's approach first, as I was already leaning towards
trying something like that (and I already have an index keeping track
of the number of rows both on the page and in the database). I think
I might be lucky in this case and not have to deal with the issue
shimmyshack raised, of buttons becoming dissociated from the correct
rows in the database, since, in this application, rows cannot be
deleted - only added or edited. Also, I think that I won't have to
deal with more than 20 to 40 rows of data at a time- so the issue of
too much data might also be avoided. Though if it becomes an issue, I
might be able to limit it further.

Apr 19 '07 #6
On Apr 19, 2:57 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
shimmyshack wrote:
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
sgotte...@yahoo.com wrote:
Hello,
If you could assist me with the following situation, I would be very
grateful.
I have a table of data retrieved from database displayed on screen.
To each row of data, I have added action buttons, such as "Edit",
"Add", and "Comment". Since I do not know how many rows of data will
be retrieved - and therefore how many buttons I need - I am using
button arrays for each button, like so:
echo "<input type=\"submit\" value=\"Comment\" name=\"Comment[]\" />";
In the php file that processes the input from this form, I have the
following code, which I was under the impression would give me the
index in the Comment array of the button that was fired.
if (isset($_POST['CommentMedicalHistory']))
{
$indexOfComment = each($_POST['CommentMedicalHistory']);
echo "index = {$indexOfComment['key']}";
}
Unfortunately, it is returning 0 as the index all the time, even when
I do not click on the Comment button in the first row.
Do you know by any chance how I could get the correct index of the
button that was pressed from the array?
Thank you, once again, for any assistance that you can provide,
Simon Gottesman
Simon,
Since you can only press one button to submit your form, you will only
get one button back - and it's index will always be zero. In the case
of a submit button, the brackets in 'name="Comment[]"' are superfluous -
you can't get back more than one button.
What you want is to get the id of the row (you do have a unique ID for
each row, right?) and use it in your name, i.e.
" ... name=\"comment[$id]\" ... "
Now you can get the $_POST['comment'] array and check your key to get
the id of the row.
No javascript or DOM needed.
Of course, there are other ways, but I like this one.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
i suppose it could be added that the [] technique /can/ be very useful
if you are making many comments at once, which is what I assumed.
another eg. When you are /submitting/ a lot of inputs each with unique
values which taken together mean something, for instance a series of
ordered triples, like 3D coordinates.
As Jerry points out, you don't need js if you print out the full DOM
in markup, you are advised to use paging with a LIMIT BY clause in
your sql, to ensure things don't grow unmanageably as the data in the
table grows.

He doesn't need the full DOM at all. Just use the row id as the index
to the array.

There needs to be some unique way to identify the row in the database.
Otherwise you can get the wrong row, i.e. if the database has changed as
you noted.

Whether it's an autoincrement or other type of column, that identifier
can be used as the index to the array. Then it's easy to retrieve the
correct row all the time.

And I agree - he needs to limit the amount of data returned now, not later.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
just to clarify, with regard mentioning DOM, I simply meant that the
total load of markup could become large, vs changing the DOM at run
time in response to user actions, since as we know the only number to
keep track of is the id. I guess like a long thread in google groups,
of course changing at runtime is not appropriate if you need
accessibility in the app.

Apr 19 '07 #7

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

Similar topics

4
by: PhilC | last post by:
Hi Folks, If I have an array holding a pair of numbers, and that pairing is unique, is there a way that I can find the array index number for that pair? Thanks, PhilC
2
by: deko | last post by:
Can I return the index number of an array if all I have is the element? For example, if I want to index the alphabet, I can put the letters in the array: Dim varLtr As Variant varLtr =...
2
by: Maziar Aflatoun | last post by:
Hi, Does anyone know how I can return the index number of a ListBox? Ex. How do I use lbxMyListBox.Items.IndexOf to search for the item that has a Text="Name" Thanks Maz.
1
by: Cordine | last post by:
i have the data row object & the data table object. I want to determine what the index position of this datarow object is in the containing table. How can i determine this??? i.e, using the...
3
by: Programatix | last post by:
Hi. I'm using a strongly typed dataset and I would like to get the index number of a column from a datarow. Is that possible? I would like to avoid using expression like this, ...
6
by: TB | last post by:
Hi All: Here´s a very simple question: I have created a datatable inside a dataset, and subsequently selected a particular row using certain criteria. How do get the index number of that...
3
by: Brian Piotrowski | last post by:
Hi All, I've probably done this before, but for the life of me I can't remember how I did it. I need to move values from a DB table into an array to be used for other queries. The number of...
1
by: Briansmi1116 | last post by:
I have a database, I have been working on, and I would like to be able to search for a record, by typing in the index number to display all of the information. The index number of the table, is the...
1
by: =?Utf-8?B?dmJTdHVkZW50?= | last post by:
Dear All, I have textbox in my form .. I enter the student name in the text e.x (vbstudent) I want to sign textbox data to array, each letter in one index. ex array(0)=v array(1)=b
2
by: Ahmad Sheeraz Saeed | last post by:
i am new to C# 2005 i created the array of text boxes like this numerictextbox1.NumericTextBox PrReading = new numerictextbox1.NumericTextBox; what i want to know, is it possible for me to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.