update query based on array
| From: | Jason Dulberg | Date: | Mon, 09 Dec 2002 23:06:37 +0000 |
| Subject: | update query based on array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-127566@lists.php.net to get a copy of this message | ||
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>
<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.
Here's what I'm using for the sql query:
while(list($key,$val)=each($rankid)) {
$upd=mysql_query("UPDATE ranking SET category='$category', rank='$rank'
WHERE pid=$val");
}
If anyone has any suggestions for fixing this problem, please let me know :)
THanks
__________________
Jason Dulberg
Extreme MTB
http://extreme.nas.net