How popular is an array with the registered bank records?

3

I have a box that shows the records that will be inserted into the database. But I'd like to make a change to that data that was entered. So I wanted to know how to make the records that are in the bank table popular in box.

Code:

<table border="0" align="center" height="100">
    <tr>
        <td>   
            <font face="arial" align="center" valign="middle" color="blue" size="-1">PATRIMÔNIO</font><br>
            <input type="text" name="tx_patr" id="id_patr" maxlength="12" size="12" style="font-size:11; color:Black;" onkeypress="return SomenteNumero(event);" onkeyup="Mascara(this,Patri);" value="">
            <input type="button" onClick="move_patr_seri(this.form.tx_patr,this.form.cb_Patr);limpa_patr();" value=">>">
            <br>
            <select multiple size="7" name="cb_Patr" style="width:300"></select>
            <br>
            <input type="button" align="center" valign="middle" onClick="tira(this.form.cb_Patr)" value="<<">
            <br>
        </td>
    </tr>
 </table>

Then it creates an input and a box where the input will be where the user types the data that will appear in the box!

Adding box example

I was able to create a select that takes the data and inserts it into the box:

<table border="0" align="center" height="100">
    <tr>
        <td>   
            <font face="arial" align="center" valign="middle" color="blue" size="-1">PATRIMÔNIO</font><br>
            <input type="text" name="tx_patr" id="id_patr" maxlength="12" size="12" style="font-size:11; color:Black;" onkeypress="return SomenteNumero(event);" onkeyup="Mascara(this,Patri);" value="">
            <input type="button" onClick="move_patr_seri(this.form.tx_patr,this.form.cb_Patr);limpa_patr();" value=">>">
            <br>
            <select multiple size="7" name="cb_Patr" style="width:300">
            <?
                $w_querybusca="SELECT 
                                sai_cad_patr_seri.tx_num_patr
                                FROM 
                                sai_cad_patr_seri 
                                WHERE 
                                sai_cad_patr_seri.fk_seq_cara_peri = '$arr_w_param[17]'";     
                                $w_queryresultado=f_class_conecta_bd($w_querybusca);            

                while($w_registro = pg_fetch_object($w_queryresultado))
                {
                    print('<option value="'.$w_registro->fk_seq_cara_peri.'">'.trim($w_registro->tx_num_patr).'</option>'."\n");
                }
                ?>
                </select>                   
            <br>
            <input type="button" align="center" valign="middle" onClick="tira(this.form.cb_Patr)" value="<<">
            <br>
        </td>

But the data that is in the box is not in my data manipulation array (which stores the data entered by the user), for me to insert the populated data of the box in the array I should do as? >

Insert the data into the array:

function move_patr_seri(Origem, Destino)
{
    var w_valor = Origem.value;
    var w_tipo;
    w_tipo = "S";

     if((Destino.name == "cb_Seri") && (Destino.options.length == w_cont))
        { return false;} 
     if((Destino.name == "cb_Patr") && (Destino.options.length == w_cont))
        { return false;}          

    if(Origem.name == "tx_patr")
        {
        w_tipo = "P";
        if (w_valor.length < 12 )
           {
           alert("Patrimônio obrigatório com 12 digitos!!");
           document.forms['sai_frm_incl_patr_seri'].tx_patr.focus();
           return false;
           }
        }

    if (w_Cont_Qtde <=  w_Qtde_Peri - 1)
       {
        if ((v_patr.indexOf(w_tipo+w_valor) == -1) && (w_valor != ""))
        {
            var opt = document.createElement("option"); 
            opt.text = w_valor ;
            opt.value = w_valor ;
            Destino.options.add(opt);

            v_patr[w_Cont_Qtde] = w_tipo + w_valor;             
            w_Cont_Qtde = w_Cont_Qtde + 1;
            if (Origem.name == "tx_patr"){ document.forms['sai_frm_incl_patr_seri'].tx_patr.focus();}
            else { document.forms['sai_frm_incl_patr_seri'].tx_seri.focus();    }       
            return true;
        }
        else
        {
            alert("Patrimônio OU Serial já existe OU não é válido!");
            return true;
        }
      }

    else
    if(w_ver == 1){
        alert("Quantidade atingida!");
        if(confirm("Deseja inserir a mesma quantidade para ambos?") == true)
        {
            w_cont = w_Qtde_Peri;
            w_ver = 0;
            w_Qtde_Peri = w_Qtde_Peri + w_Qtde_Peri;
            return true;
        }
    }
    else
        alert("Quantidade informada ja Incluida !!!");
   return true; 
}

The array is v_patr !

    
asked by anonymous 07.10.2014 / 17:53

1 answer

3

Store in a variable the records taken from the database and give echo inside the script as well, writing it as you did with HTML .

>

In the list ...

$objs = array();
while($w_registro = pg_fetch_object($w_queryresultado)) {
   $objs[$w_registro->fk_seq_cara_peri] = trim($w_registro->tx_num_patr);
   print('<option value="'.$w_registro->fk_seq_cara_peri.'">'.trim($w_registro->tx_num_patr).'</option>'."\n");
}

And in the script part ...

<script>
<?php
$v_patr = '';
foreach ($objs as $obk => $obn){
  $v_patr .= "'{$obk}{$obn}', ";
}
$v_patr = trim($v_patr, ', ');

echo 'v_patr = ['.$v_patr.'];'.PHP_EOL;
echo 'w_Cont_Qtde  = '.count($objs).';'.PHP_EOL;
?>
function move_patr_seri(Origem, Destino)
{
.
.
.

I do not quite understand your rule, but it just adapts it the way it suits you best.

    
07.10.2014 / 19:39