Hi,
i made a form so i can update database values. So far it works fine if i want to update 2 field values from one single row, but the problem is that i have over 90 rows! so its out of the question to define all the $_POST[”] for every one of them, thats why im trying to define a loop in order to have all those variables generated automatically but i cant get it to work:
[code=php]
$str = “”;
$totalrows=”SELECT * FROM rooms”;
$result=mysql_query($totalrows);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$row_room=mysql_result($result,$i,”room”);
$row_price=mysql_result($result,$i,”price”);
$row_status=mysql_result($result,$i,”status”);
$number = preg_replace(“/[^0-9]/”, ”, $row_room);
$ud_price[$row_room] = $_POST[‘ud_price_’$row_room]; <— this line
$action .= “UPDATE rooms SET price = ‘$ud_price[$row_room]’, status = ‘$ud_status[$row_room]’ WHERE room = ‘$row_room'”; <– and this line
$str .= <<<EOF
<TR>
<TD>$number</TD>
<TD><INPUT type=”text” name=”ud_price_$row_room” size=”3″ value=”$row_price”></TD>
<TD>
<SELECT name=”ud_state_$row_room”>
$state[$row_room]
</SELECT>
<input type=”hidden” name=”ud_room_$row_room” value=”$row_room”>
</TD>
</TR>
the code is actually longer but the part that needs to be fixed is marked with “<–“. The form would work (without the marked part) if i do this:
[code=php]
$ud_room_201=$_POST[‘ud_room_201’];
$ud_price_201=$_POST[‘ud_price_201’];
$ud_status_201=$_POST[‘ud_status_201’];
$ud_room_202=$_POST[‘ud_room_202’];
$ud_price_202=$_POST[‘ud_price_202’];
$ud_status_202=$_POST[‘ud_status_202’];
and so on…
$action1 = “UPDATE rooms SET price = ‘$ud_price_201’, status = ‘$ud_status_201’ WHERE room = ‘$ud_room_201′”;
$action2 = “UPDATE rooms SET price = ‘$ud_price_202’, status = ‘$ud_status_202’ WHERE room = ‘$ud_room_202′”;
and so on…
mysql_query($action);
mysql_query($action2);
and so on…
but i guess there is a much more simple way to do it, isnt it? just the same way i did to generate the <td></td> for each row in the table. Can you please give me so hints?
thank you!