On Tuesday 10 December 2002 07:06, Jason Dulberg wrote:
> I am displaying a list of data (from an sql query) and some of the fields
> in that list are editable through a form. If the user chooses to edit one
> or more of the rows of data, they must click on a checkbox to add that row
> to an "update array". The problem is that when I read that array to pass to
> an UPDATE sql statement, it only passes the last entry of the array.
> Here's an example of the data being passed:
> 13 - 4 - UPDATE ranking SET category='Prep School', rank='30' WHERE pid=4
> 14 - 169 - UPDATE ranking SET category='Prep School', rank='30' WHERE
> pid=169
> 15 - 166 - UPDATE ranking SET category='Prep School', rank='30' WHERE
> pid=166
> The above is created based on the following html code:
> //the last row
> <input type="text" name="category" value="Prep School">
> <input type="text" name="rank" value=30 size=4>

The above two are named the same for ALL your rows so it will take the value 
of the last row, hence your problem. In general, each of your form elements 
must have a unique name.

> <input type="checkbox" name="rankid[15]" value="166">
> So as you can see, its only reading the last row and assigning its values
> to the data above as well.

Name your rows something along the lines of:

<input type="text" name="rows[15][category]" value="Prep School">
<input type="text" name="rows[15][rank]" value=30 size=4>
<input type="checkbox" name="rows[15][rankid]" value="166">

<input type="text" name="rows[16][category]" value="Prep School">
<input type="text" name="rows[16][rank]" value=30 size=4>
<input type="checkbox" name="rows[16][rankid]" value="166">

Then to process:

  foreach ($rows as $row) {
    echo "$row['category'], $row['rank'], $row['rankid']";

Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

Fudd's First Law of Opposition:
        Push something hard enough and it will fall over.

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

Reply via email to