Forum Moderators: coopster
$request=mysql_query("SELECT * FROM stock ORDER BY category, code",$db);
echo"<form name=\"stock\" action=\"stock/modules/\" method=\"post\">";
echo"<table border=\"1\"><tr><td>Category</td><td>Code</td><td> </td></tr>";
while($row=mysql_fetch_array($request,$db)){
$id=$row["id"];
$category=$row["category"];
$code=$row["code"];
echo"<tr><td>$category</td><td>$code</td><td><INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\"><INPUT TYPE=\"SUBMIT\" NAME=\"op\" VALUE=\"Edit\"></td></tr>";
}
echo"</form>";
I can retrive the data well, but the 'id' value attached with each button always cache with the id of my last record, hence I always edit the wrong record. I think that is some problem with my while loop, but I can't find it out. Anyone can help? Any mistake with my script? Any tutorial/ example?
Thanks.
mysql_fetch_array($request)
or alternately (if you want to define how it fetches the array):
mysql_fetch_array($request, MYSQL_ASSOC)
mysql_fetch_array($request, MYSQL_NUM)
I'm not sure if that's causing the 'duplication', but I'd hazard a guess that it might be (possibly confusing the function...?) Test it out see how you go.
mysql_fetch_array($request, MYSQL_ASSOC)
but I still get the same result. My problem is not with the data retrieved but is the value of 'id' which in hided when user click ob the 'Edit' button, the value will be pass to the edit function. I have checked out, it have got passing the wrong value, passed the id of last record for each record instead of each id for each record. In other word, no matter which record they click on, they will passing the id for last record.