problema la recibir los datos de los list box
Publicado por Hfr (93 intervenciones) el 18/06/2016 16:48:09
Hola chicos.
bueno la otra vez cree una dos list box para paar datos entre ellos. pero estoy teneindo un problema cuando recibo los datos.
de los list box.
cuando paso del list 1 al list box 2 y envio los datos funciona bien,
pero cuado paso del list 1 al list box 2 y devuelvo deñl dos al 1 asuminedo que uno se equivoco y envio la opcion equivocada.
enhtonces si en total en lisbox 2 quedao 3 elementos
el for tan solo muestra un elemento y no los 3 o el total con el que halla quedado
y esto afecta un insert dinamico para guardar eso datos.
aquí les dejo el código completo.
bueno la otra vez cree una dos list box para paar datos entre ellos. pero estoy teneindo un problema cuando recibo los datos.
de los list box.
cuando paso del list 1 al list box 2 y envio los datos funciona bien,
pero cuado paso del list 1 al list box 2 y devuelvo deñl dos al 1 asuminedo que uno se equivoco y envio la opcion equivocada.
enhtonces si en total en lisbox 2 quedao 3 elementos
el for tan solo muestra un elemento y no los 3 o el total con el que halla quedado
1
2
3
4
for ($d=0; $d<count($dato); $d++)
{
echo "dato nuermo".$d." ".$dato[$d]."<br>";
}
y esto afecta un insert dinamico para guardar eso datos.
aquí les dejo el código completo.
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
212
213
214
215
216
217
218
219
220
221
222
<html>
<head>
<SCRIPT language="javascript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name="chkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
var cell3 = row.insertCell(2);
var element2 = document.createElement("input");
element2.type = "text";
element2.name = "mts[]";
cell3.appendChild(element2);
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
</SCRIPT>
<script>
function listbox_move(listID,direction){
var listbox=document.getElementById(listID);
var selIndex=listbox.selectedIndex;if(-1==selIndex){alert("Please select an option to move.");
return;
}
var increment=-1;if(direction=='up')
increment=-1;
else
increment=1;
if((selIndex+increment)<0||(selIndex+increment)>(listbox.options.length-1))
{
return;
}
var selValue=listbox.options[selIndex].value;
var selText=listbox.options[selIndex].text;listbox.options[selIndex].value=listbox.options[selIndex+increment].value
listbox.options[selIndex].text=listbox.options[selIndex+increment].text
listbox.options[selIndex+increment].value=selValue;listbox.options[selIndex+increment].text=selText;listbox.selectedIndex=selIndex+increment;
}
function listbox_moveacross(sourceID,destID){
var src=document.getElementById(sourceID);
var dest=document.getElementById(destID);
for(var count=0;count<src.options.length;count++)
{
if(src.options[count].selected==true)
{
var option=src.options[count];
var newOption=document.createElement("option");
newOption.value=option.value;
newOption.text=option.text;
newOption.selected=true;
try
{
dest.add(newOption,null);
src.remove(count,null);
}
catch(error){
dest.add(newOption);src.remove(count);
}
count--;
}
}
}
function listbox_selectall(listID,isSelect)
{var listbox=document.getElementById(listID);
for(var count=0;count<listbox.options.length;count++)
{
listbox.options[count].selected=isSelect;
}
}
</script>
</head>
<body>
<form ACTION ="XX.PHP" METHOD ="POST">
<select id="s" size="10" multiple="m[]" >
<option value="dato1">dato1</option>
<option value="dato2">dato2</option>
<option value="dato3">dato3</option>
<option value="dato4">dato4</option>
<option value="dato5">dato5</option>
<option value="dato6">dato6</option>
<option value="dato7">dato7</option>
<option value="dato8">dato8</option>
<option value="dato9">dato9</option>
</select>
<a href="#" onclick="listbox_moveacross('s', 'd')">>></a>
<a href="#" onclick="listbox_moveacross('d', 's')"><<</a>
<select id="d" size="10" multiple="" name ="p[]" >
</select>
<br>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
<TABLE id="dataTable" >
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>1</TD>
<TD> <INPUT type="text" /> </TD>
</TR>
</TABLE>
<BR>
<INPUT TYPE="submit" value="click">
</form>
</body>
</html>
<?php
include ('php/con_mysql.php');
$link = new conexion();
$conn = $link->conectar();
$idnnja='1234567890';
$dato =$_POST['p'];
for ($d=0; $d<count($dato); $d++)
{
echo "dato nuermo".$d." ".$dato[$d]."<br>";
}
$metas = $_POST['mts'];
$realizacion ="JASLÑKDJASLKD";
$query ='INSERT INTO pl_vidasaludable (id_nnja,realizacion,';
for ($i=0, $size = count($dato); $i<$size;$i++){
$query.= ' dato'.($i+1).', metas'.($i+1);
if ( $size > $i+1 ){
$query .= ',';
}
}
$query .= ') VALUES ('.$idnnja.',\''.$realizacion.'\''; // aqui ingreso el id pero falta la coma
for ($i=0, $size = count($dato); $i<$size;$i++){
if ($i == 0){ // como solo sera al inicio del array coloco como condicion que sea en el primer indice
$query.= ', '; // aca ingreso la coma
}
$query .= '\''.$dato[$i].'\', \''.$metas[$i].'\'';
if ( $size > $i+1 ){
$query .= ', ';
}
}
$query.= ');';
$inser=mysqli_query($conn,$query);
if ($inser)
{
echo "exito<BR>";
}
else {
echo "<BR>no insertado<BR>";
}
echo $query;
?>
Valora esta pregunta
0