Aji Andri <[EMAIL PROTECTED]> wrote on 04/15/2005 03:49:52 PM: > this is my prosedure.... > 1st. I'm, selecting base on std_nis=111 in > STY_RANK_200501 > 2nd. looping and fetching echoing > ---- looping and fetching echoing---- > while ($nline = mysql_fetch_array($result)) { > echo $nline["std_value"] > echo $nline["std_item"] > } > ----- end looping and fetching echoing ----- > 3rd. result of 2nd stage is > ----- result--------- > std_nis std_class std_item std_value > 111 1 1 8 -----1st row > 111 1 2 7 -----2nd row > 111 1 5 6 -----3rd row > 111 1 4 9 -----4th row > ----end result------- > 4th. updating > the page(web page) is show like this with new value > commnent > > ---start web page view ------- > Update Student Value for Student NIS 111 in Class 1 > Study(define as std_item) Value(define as std_value) > 1 7 <-------this new > value > 2 4 <-------this new > value > 5 9 <-------this new > value > 4 10 <-------this new > value > > Submit Reset > > ---end web page view-------- > so the new value will update the old value of each > study item using > > ---updating script---- > $query = "update STY_REPORT_200501 set std_value='" . > $nenilai . "', std_nis='" . $nenis . "', std_item='" . > $neitem . "', std_entusr='" . $neentusr . "' where > std_item=".$neitem ; > ----- end updating script------- > > and that the complate way I'm doing it, but when user > click the submit result is like this > > ---after submiting----- > std_nis std_class std_item std_value > 111 1 1 8 -----1st row > 111 1 1 8 -----2nd row > 111 1 1 8 ------3rd row > 111 1 1 8 -----4th row > ----- end submitting ---------- > > so how I had to doit so each row will update base on > it std_item, not make it all as std_item=1 and value > is 8 ? > > >
OK, I see it now. Your problem is that your UPDATE statement is not selective enough. It will UPDATE all of the rows that match the WHERE condition. If you want it to update just a particular row, you need to be able to isolate it through WHERE conditions like this UPDATE STY_REPORT_200501 SET ... WHERE std_item = <some value> AND std_class= <some other value> AND ... (continue adding conditions until you reach a combination that uniquely identifies the particular record you want to update. When you say UPDATE ... ... WHERE std_nis = 111; That WHERE clause matches 4 rows of data. That's why all 4 rows are changed. But if you say UPDATE ... ... WHERE std_nis = 111 AND std_item=1; That WHERE clause can only match one row of data (from your example). Only one row would have been affected by the UPDATE. Does this make sense? Shawn Green Database Administrator Unimin Corporation - Spruce Pine