473,732 Members | 2,207 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['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 2723
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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['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*******@attgl obal.net
=============== ===
Apr 19 '07 #3
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attg lobal.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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['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...@attgl obal.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...@attg lobal.netwrote:
>sgotte...@yaho o.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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['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...@attg lobal.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*******@attgl obal.net
=============== ===
Apr 19 '07 #5
On Apr 19, 9:57 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
shimmyshack wrote:
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attg lobal.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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['key']}";
}
Unfortunatel y, 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...@attgl obal.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...@attgl obal.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...@attg lobal.netwrote:
shimmyshack wrote:
On Apr 19, 5:28 am, Jerry Stuckle <jstuck...@attg lobal.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['CommentMedical History']))
{
$indexOfComment = each($_POST['CommentMedical History']);
echo "index = {$indexOfCommen t['key']}";
}
Unfortunatel y, 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...@attgl obal.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...@attgl obal.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
11729
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
7117
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 = Array("A", "B", "C", "D", "E", "F", "G", _ "H", "I", "J", "K", "L", "M", "N", _ "O", "P", "Q", "R", "S", "T", "U", _ "V", "W", "X", "Y", "Z")
2
1758
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
1419
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 row index number i can get hold of the row object DIM oRow as DataRow = oDataTable.Rows(nIndex)
3
8800
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, myTable.Columns.IndexOf("myColumnName") Thanks.
6
5694
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 particular row? There doesn´t seem to be property like "mydatable.currentlyselectedrowindex" or "myrow.indexnumber". Any suggestions will be highly appreciated.
3
1909
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 records will vary, so I need to make the array dynamic. Can someone remind me how I can increment the index when I write a new record? Here's a sample of the code I wrote: If rsGETKD.EOF = False Then Dim KDLOTSQ
1
1839
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 primary key. I would like to either click in the box on the form and enter the number I want to jump to, or double click in the box to open a form to enter the number I want to jump to. Is this possible? Let me know if you need more information,...
1
6523
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
8257
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 display the index number of the text box in which the focus is. for example if i am in first text box the index number will be 0 and if i am in second text box the index number will be 1. I do it this is vb6 but don't know how to do it in c#. Thanks
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.