Foros del Web » Programando para Internet » PHP »

Como realizar esto?

Estas en el tema de Como realizar esto? en el foro de PHP en Foros del Web. Hola que tal. Tengo el siguiente codigo: Código PHP: <html> <body>     <script type="text/javascript"> function insertar() {     obj=document.getElementById('sel1');     if (obj.selectedIndex==-1) return;     valor=obj.value;     txt=obj.options[obj.selectedIndex].text;     obj.options[obj.selectedIndex]=null;     obj2=document.getElementById('sel2');     obj3=document.getElementById('sel3');     obj4=document.getElementById('sel4');     opc = new Option(txt,valor);     opc1 = new Option(txt,valor);     opc2 = new Option(txt,valor);     eval(obj2.options[obj2.options.length]=opc); ...
  #1 (permalink)  
Antiguo 21/06/2011, 09:32
 
Fecha de Ingreso: mayo-2011
Mensajes: 55
Antigüedad: 13 años
Puntos: 1
Como realizar esto?

Hola que tal.

Tengo el siguiente codigo:

Código PHP:
<html>
<body>

    <script type="text/javascript">
function insertar() {
    obj=document.getElementById('sel1');
    if (obj.selectedIndex==-1) return;
    valor=obj.value;
    txt=obj.options[obj.selectedIndex].text;
    obj.options[obj.selectedIndex]=null;
    obj2=document.getElementById('sel2');
    obj3=document.getElementById('sel3');
    obj4=document.getElementById('sel4');
    opc = new Option(txt,valor);
    opc1 = new Option(txt,valor);
    opc2 = new Option(txt,valor);
    eval(obj2.options[obj2.options.length]=opc);
    eval(obj3.options[obj3.options.length]=opc1);
    eval(obj4.options[obj4.options.length]=opc2);
}
function vaciar() {
  obj2 = document.getElementById('sel2');
  obj3 = document.getElementById('sel3');
  obj4 = document.getElementById('sel4');
  num = obj2.options.length;
  for (i=num-1; i>=0; i--) {
    txt=obj2.options[i].text;
    valor=obj2.options[i].value;
    obj2.options[i]=null;
    obj=document.getElementById('sel1');
    opc = new Option(txt,valor);
    eval(obj.options[obj.options.length]=opc);
  }
  num2 = obj3.options.length;
  for (i=num2-1; i>=0; i--) {
    txt=obj3.options[i].text;
    valor=obj3.options[i].value;
    obj3.options[i]=null;
    obj=document.getElementById('sel1');
    opc = new Option(txt,valor);
    eval(obj.options[obj.options.length]=opc);
  }
  num3 = obj4.options.length;
  for (i=num3-1; i>=0; i--) {
    txt=obj4.options[i].text;
    valor=obj4.options[i].value;
    obj4.options[i]=null;
    obj=document.getElementById('sel1');
    opc = new Option(txt,valor);
    eval(obj.options[obj.options.length]=opc);
  }
}
</script>
    <form id="form1" name="form1" method="post" action="">
      <div>
      <center>
      <label for="lista">Que Desea Realizar?</label>
      </center>
      </div>
      <div>
      <center>
      <select name="lista" id="lista" style='width:200px; height:30px' 'text-align:center;'>
        <option value="1"> Seleccionar Opcion</option>
        <option value="2">Sumar</option>
        <option value="3">Agrupar</option>
        <option value="4">Contar</option>
      </select>
      </center>
      </div>
      <br />

<div class="h1s" style="float: left;"  align="right">
  <label>Campos</label>
         <br>
<?php
          
//Te conectas a tu base de datos Ej:

$linkmysql_connect("localhost","root","");

//Realizas tu consulta SQL Ej:

$result=mysql_query("SELECT COLUMN_NAME FROM information_schema.`COLUMNS` WHERE TABLE_SCHEMA = 'bd' AND TABLE_NAME = 'julio'" ,$link);

//Llenas el combo

if ($row mysql_fetch_array($result)){ 
echo 
'<select id="sel1" size="10" style="width:150;" multiple>';
do {
       echo 
'<option value= "'.$row["COLUMN_NAME"].'">'.$row["COLUMN_NAME"].'</option>';
} while (
$row mysql_fetch_array($result)); 
echo 
'</select>';

}
          
?>
</div>
    <div style="float: left; padding-top: 20px;" align="center">
         <input name="button" type="button" onClick="insertar()" value="Incluir >">
        <br>
         <input name="button" type="button" onClick="vaciar()" value="<< Vaciar">
</div>
      <div style="float: left;" align="center">
      <label>Campos Seleccionados<br>
        <span style="float: left;">
            <select name="select" size="10" multiple id="sel2" style="width:150;">
          </select>
        </span>
      </label>
          <input type="hidden" name="subcategoria" value="">
          <input type="hidden" name="of_area" value="">    
    </div>
    </br>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <label for="cmbx2">
  <div align="center">&nbsp; <span class="negritas">Condicion Entre Campos</span></div>
<label for="cmbx2"></label>
    <div align="center">
    <form id="form1" name="form1" method="post" action="">
<label for="cmbx"></label>
          <select name="cmbx" id="sel3" style='width:180px;'>
          </select>
<label for="cmbx3"></label>
      <select name="cmbx2" id="cmbx3" style='width:85px;'>
        <option>--------------------------------------</option>
        <option value="=">Igual</option>
<option value="&lt;">Menor</option>
<option value="&gt;">Mayor</option>
        <option value="!=">Diferente</option>
      </select>
<label for="txt"></label>
          <input type="text" name="txt" id="txt" />
      </div>
      <br />
      <div align="center">
          <select name="cmbxand" id="cmbxand" style='width:50px;'>
            <option>-------------------------</option>
            <option value="&amp;">And</option>
            <option value="|">Or</option>
          </select>
      </div>
      <br />
      <div align="center">
    <form id="form1" name="form1" method="post" action="">
<label for="cmbx"></label>
          <select name="cmbx" id="sel4" style='width:180px;'>
          </select>
      <label for="cmbx3"></label>
      <select name="cmbx2" id="cmbx3" style='width:85px;'>
        <option>-------------------------------------</option>
        <option value="=">Igual</option>
<option value="&lt;">Menor</option>
<option value="&gt;">Mayor</option>
        <option value="!=">Diferente</option>
      </select>
      <label for="txt"></label>
          <input type="text" name="txt" id="txt" />
      </div>
      <br />
      <div align="center">
      <input type="submit" class="greenButton" value="Buscar" />
      </div>
</form>
</body>
</html>
En si esto es una busqueda avanzada en una base de datos en mysql en el select multiple "campos" se imprimen los campos que existen en mi base de datos en mysql luego el usuario elige los campos que requiere y los pasa al segundo select multiple por medio del boton incluir lo que quiero hacer con esto es un query en donde el usuario siga estos pasos:

1.- primero el usuario elija si quiere sumar contar o solo agrupar campos.
2.- luego que elija los campos que necesita de la base de datos. Al momento de darle click al boton incluir no solo se van los campos hacia el segundo select multiple si no que tambien aparecen en los combobox de abajo los dos mas largos para realizar la condicion.
3.- en los combox largos toma el campo que desea hacer la condicion elige si es igual, menor diferente etc a el dato que ponga en el textfield o input
4.- si desea una condicion mas larga pone el and o el or segun lo desea y realiza la segunda condicion.

mi pregunta es como realizo la validacion de todo como valido el select multiple para que obtenga el nombre de todos los campos que selecciono el usario y por medio de eso realice el query para saber cuantos campos necesita la tabla al momento de imprimir
  #2 (permalink)  
Antiguo 21/06/2011, 09:39
Avatar de iviamontes  
Fecha de Ingreso: enero-2011
Ubicación: $cubano->Arg->Mendoza
Mensajes: 1.184
Antigüedad: 13 años, 3 meses
Puntos: 209
Respuesta: Como realizar esto?

bueno el tema de validacion es js, no es este foro, separa tus dudas one by one
y para hacer tu consulta dinamica, tienes que recorrer todos lo que te llega por post y así ir armandola

foreach($_POST as key => value)
{
// tus cosas
}

Etiquetas: realizar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:52.