PHP - Cargar lista desplegable dinamica para modificar

 
Vista:

Cargar lista desplegable dinamica para modificar

Publicado por Roberto (2 intervenciones) el 07/04/2016 10:31:23
Buenos días, este foro me ha ayudado en multitud de ocasiones sin tener que pedir ayuda; pero en este caso no veo la solución.
Me explico tengo dos listas desplegable que toma los datos de dos tablas todo funciona correctamente salvo a la hora de buscar un registro , no soy capaz de hacer que las listas (solo he puesto código para la primera) "Centro de trabajo"

Espero que alguien me ilumine un poco, gracias.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
mysql_select_db($database_local, $local);
$query_Rec_tiendas = "SELECT * FROM tiendas";
$Rec_tiendas = mysql_query($query_Rec_tiendas, $local) or die(mysql_error());
$row_Rec_tiendas = mysql_fetch_assoc($Rec_tiendas);
$totalRows_Rec_tiendas = mysql_num_rows($Rec_tiendas);
 
mysql_select_db($database_local, $local);
$query_Rec_fp = "SELECT desc_fp FROM f_pagos";
$Rec_fp = mysql_query($query_Rec_fp, $local) or die(mysql_error());
$row_Rec_fp = mysql_fetch_assoc($Rec_fp);
$totalRows_Rec_fp = mysql_num_rows($Rec_fp);
?>
<?php
$var="";/*codigo*/
$var1="";/*centro de trabajo*/
$var2="";/*horas trabajo*/
$var3="";/*horas desto*/
$var4="";/*gastos matrial*/
 
 
if(isset($_POST["btn1"])){
	$btn=$_POST["btn1"];
	$bus=$_POST["textbus"];
	if($btn=="Buscar"){
 
	$sql="select * from trabajo_tiendas_misstic where idpa='$bus'";
	$cs=mysql_query($sql,$local);
	while ($result=mysql_fetch_array($cs)){;
		$var=$result[0];
		$var1=$result[1];
		$var2=$result[2];/*centro de trabajo*/
		$var3=$result[3];
		$var4=$result[4];
		$var5=$result[5];
 
 
	    }
	}
	if($btn=="Nuevo"){
 
 
	$sql="select count(idpa),max(idpa) from trabajo_tiendas_misstic";
	$cs=mysql_query($sql,$local);
	while ($result=mysql_fetch_array($cs)){
		$count=$result[0];
		$max=$result[1];
	}
	if ($count==0){
		$var=1;
	   }
	   else {
		   $var=($max+1);
 
	   }
	}
		if($btn=="Añadir"){
		$cod=$_POST["textcod"];
		$fecha=$_POST["textfecha"];
		$centro=$_POST["select"];
		$horatr=$_POST["texthtr"];
		$horads=$_POST["texthds"];
		$material=$_POST["textgmat"];
 
 
	$sql="insert into trabajo_tiendas_misstic values ('$cod','$fecha','$centro','$horatr','$horads','$material')";
	$cs=mysql_query($sql,$local);
	echo "<script> alert('Se añadido; correctamente');</script>";
 
}
		if($btn=="Modificar"){
		$cod=$_POST["textcod"];
		$fecha=$_POST["textfecha"];
		$centro=$_POST["select"];
		$horatr=$_POST["texthtr"];
		$horads=$_POST["texthds"];
		$material=$_POST["textgmat"];
 
 
		$sql="update trabajo_tiendas_misstic set Fecha='$fecha',Tienda='$centro',Horas_trabajo='$horatr',Horas_desplazamiento='$horads',Material='$material' where idpa='$cod'";
 
		$cs=mysql_query($sql,$local);
		echo "<script> alert('Actualizado correctamente');</script>";
		}
	if($btn=="Eliminar"){
		$cod=$_POST["textcod"];
 
		$sql="delete from trabajo_tiendas_misstic where idpa='$cod'";
 
		$cs=mysql_query($sql,$local);
		echo "<script> alert('Eliminado correctamente');</script>";
		}
 
	}
 
?>
<form name="fe" action="" method="post">
<!--parte buscar-->
<center>
<table width="200" border="3">
  <tr>
    <td>Buscar</td>
    <td><input type="text" name="textbus"/></td>
    <td><input type="submit" name="btn1" value="Buscar"/></td>
    </tr>
    <tr>
    <td>Codigo</td>
    <td><input type="number" name="textcod" value="<?php echo $var?>" /></td>
  </tr>
</table>
</center>
<!--Parte inserccion Datos-->
<center>
<table width="862" border="3">
  <tr>
    <td width="206">Fecha</td>
    <td colspan="2"><input type="date" name="textfecha" value="<?php echo $var1?>"/></td>
  </tr>
  <tr>
    <td>Centro de Trabajo</td>
    <td colspan="2"><select  name="select" id="select">
      <?php
do {
?>
      <option value="<?php echo $row_Rec_tiendas['Nombre']?>"><?php echo $row_Rec_tiendas['Nombre']?></option>
      <?php
} while ($row_Rec_tiendas = mysql_fetch_assoc($Rec_tiendas));
  $rows = mysql_num_rows($Rec_tiendas);
  if($rows > 0) {
      mysql_data_seek($Rec_tiendas, 0);
	  $row_Rec_tiendas = mysql_fetch_assoc($Rec_tiendas);
  }
?>
    </select></td>
  </tr>
  <tr>
    <td>Horas de trabajo</td>
    <td colspan="2"><input type="time" name="texthtr" value="<?php echo $var3?>"/></td>
  </tr>
  <tr>
    <td>Horas de Desplazamiento</td>
    <td colspan="2"><input type="time" name="texthds" value="<?php echo $var4?>"/></td>
	</tr>
  <tr>
    <td>Gastos Material</td>
    <td width="94"><select name="select5" id="select5">
      <?php
do {
?>
      <option value="<?php echo $row_Rec_fp['desc_fp']?>"><?php echo $row_Rec_fp['desc_fp']?></option>
      <?php
} while ($row_Rec_fp = mysql_fetch_assoc($Rec_fp));
  $rows = mysql_num_rows($Rec_fp);
  if($rows > 0) {
      mysql_data_seek($Rec_fp, 0);
	  $row_Rec_fp = mysql_fetch_assoc($Rec_fp);
  }
?>
    </select></td>
    <td width="144"><input type="number_format(number,2 ",", ".")" name="textgmat" value="<?php echo $var5?>"/></td>
 </tr>
</table>
<center>
 <table width="300" border="3">
  <tr align="center">
    <td colspan="2"><input type="submit" name="btn1" value="Nuevo"/><input type="submit" name="btn1" value="Añadir"/></td>
  </tr>
  <tr align="center">
    <td><input type="submit" name="btn1" value="Modificar"/><input type="submit" name="btn1" value="Eliminar"/></td>
  </tr>
  <tr>
</table>
 
</center>
</form>
<?php
mysql_free_result($Rec_tiendas);
 
mysql_free_result($Rec_fp);
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Cargar lista desplegable dinamica para modificar

Publicado por Airy Fabián (8 intervenciones) el 08/04/2016 06:25:14
Saludos, me gustaría ayudarte, pero no entiendo cual es tu problema. Dime exactamente que deseas hacer y así lo podre ver en tu código y darte una opinión!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Cargar lista desplegable dinamica para modificar

Publicado por Roberto (2 intervenciones) el 08/04/2016 07:43:13
Buenas y gracias, ahora mismo cuando busco un código todos los cuadros de texto me devuelve todos los valores de la tabla "trabajo_tiendas_misstic" que es lo que necesito; salvo el de la lista desplegable dinámica.

La lista toma los valores de la tabla "tiendas['Nombre']" , y no sé como ponerle la variable y código para que al buscar me devuelva el valor que tiene "select * from trabajo_tiendas_misstic where idpa='$bus'";"

Espero explicarme un poco mejor ahora, y gracias otra vez
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar