Ver Mensaje Individual
  #3 (permalink)  
Antiguo 16/04/2011, 07:21
Avatar de s00rk
s00rk
 
Fecha de Ingreso: octubre-2010
Ubicación: Mexico
Mensajes: 238
Antigüedad: 13 años, 6 meses
Puntos: 48
Respuesta: Update de un registro en varias filas

Bueno comienzo haciendo preguntas, el primer archivo lo de option podria ponerse simplemente con esto
Código PHP:
<select name="ordendestacado"><? for($x 0$x<=21$x++)
?>
    <option value="<?=$x?><?php if($rows['ordendestacado'] == $x)?> selected="selected"><?=$x?></option>
    <?
}
?></select>
Bueno ahora si el segundo archivo, lo siguiente esta mal:
Código PHP:
 if($_GET[$i]) 
Ya que eso no puede ser posible porque nunca le mandas una variable i o no que yo vea en el form e igualmente con lo demas de $ordendestacado, eso tampoco nunca lo declaras para ello hay que utilizar el $_POST, el igual con $count.

El codigo hasta ahi esta mal jeje

EDIT::

Fijate aver si asi te sirve
Código PHP:
Ver original
  1. <?php
  2. $host="localhost";
  3. $username="root";
  4. $password="";
  5. $db_name="sanandre_sap";
  6.  
  7.  
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10.  
  11. $sql="select *
  12. from sistema
  13. where `destacado` = 'Si'
  14. and `estado` = 'Activo'";
  15. $result=mysql_query($sql);
  16.  
  17.  
  18. $count=mysql_num_rows($result);
  19. ?>
  20. <table width="80%" border="0" cellspacing="1" cellpadding="0">
  21. <form name="form" method="post">
  22. <tr>
  23. <td>
  24. <table width="80%" border="0" cellspacing="1" cellpadding="0">
  25.  
  26.  
  27. <tr>
  28. <td align="center"><strong>Id</strong></td>
  29. <td align="center"><strong>Tipo de Inmueble</strong></td>
  30. <td align="center"><strong>Tipo de Operacion</strong></td>
  31. <td align="center"><strong>Barrio</strong></td>
  32. <td align="center"><strong>Calle</strong></td>
  33. <td align="center"><strong>Altura</strong></td>
  34. <td align="center"><strong>Actual</strong></td>
  35. <td align="center"><strong>Orden</strong></td>
  36. </tr>
  37. <?php
  38. $i = 0;
  39. while($rows=mysql_fetch_array($result)){
  40.     $r[$i]['id'] = $rows['id'];
  41.     $r[$i]['ordendestacado'] = $rows['ordendestacado'];
  42.     $i++;
  43. ?>
  44. <tr>
  45. <td align="center"><?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?></td>
  46. <td align="center"><?php echo $rows['tipoinmueble']; ?></td>
  47. <td align="center"><?php echo $rows['tipodeoperacion']; ?></td>
  48. <td align="center"><?php echo $rows['barrio']; ?></td>
  49. <td align="center"><?php echo $rows['calle']; ?></td>
  50. <td align="center"><?php echo $rows['altura']; ?></td>
  51. <td align="center"><?php echo $rows['ordendestacado']; ?></td>
  52. <td align="center"><select name="ordendestacado"><? for($x = 0; $x<=21; $x++)
  53. { ?>
  54.     <option value="<?=$x?>" <?php if($rows['ordendestacado'] == $x)?> selected="selected"><?=$x?></option>
  55.     <?
  56. }
  57. ?></select></td>
  58. </tr>
  59. <?php
  60. }
  61. ?>
  62. <tr>
  63. <td colspan="4" align="center"><input type="Submit" name="Submit" value="Submit"></td>
  64. </tr>
  65. </table>
  66. </td>
  67. </tr>
  68. </form>
  69. </table>
  70.  
  71. <?php
  72. if(isset($_POST['Submit']))
  73. {
  74.     for($x=0;$x<$count;$x++){
  75.         $sql1="UPDATE sistema SET ordendestacado='".$r[$x]['ordendestacado']."' WHERE id='".$r[$x]['id']."'";
  76.         $result1=mysql_query($sql1);
  77.     }
  78.     if($result1){
  79.         header("location:ok.php");
  80.     }
  81.     mysql_close();
  82. }
  83. ?>

Última edición por s00rk; 16/04/2011 a las 07:30