0
I have the "input1" that searches the name of a client and saves his id in the table, this search is done by autocomplete with Javascript.
Now I needed that in "input2" I received the id of the "partner" linked to the id of the client that was inserted in "input1", both belong to the same table (client and partner).
It is not necessary to show the partner name in the form, just save your id corresponding to the client id that is already displayed.
The display of the table with the client and partner column is OK, I tested with insertion of the direct partner id in the BD, I just can not through the form.
<div class="control-group">
<label for="clientes" class="control-label">Cliente</label>
<div class="controls">
<input id="cliente" type="text" name="cliente" />
<input id="clientes_id" type="hidden" name="clientes_id" value=""/>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#cliente").autocomplete({
source: "<?php echo base_url(); ?>index.php/exportacao/autoCompleteCliente",
minLength: 1,
select: function( event, ui ) {
$("#clientes_id").val(ui.item.id);
}
});
}
Controller: Export.php
public function autoCompleteCliente(){
if (isset($_GET['term'])){ //devolve indice referente ao nome do cliente
$q = strtolower($_GET['term']);
$this->fatexpo_model->autoCompleteCliente($q);
}
}
model: fatexpo_model.php
public function autoCompleteCliente($q){
$this->db->select('*');
$this->db->limit(5);
$this->db->like('nomeCliente', $q);//busca pelo nome do cliente
$query = $this->db->get('clientes');
if($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$row_set[] = array('label'=>$row['nomeCliente'],'id'=>$row['idClientes']);
}
echo json_encode($row_set);
}
}
In the image, the input stores the id = 7 corresponding to the name Bridgestone, your partner would id = 2
Everything is working, I can register and display them, I just can’t save the partner id linked to the client id I already got.
Your question is confused, let’s go in parts: you have several clients in the database (which is what is being searched for by autocomplete) and each of these clients has a field
parceiroId
, right?– Jéf Bueno
Hello, sorry, I couldn’t be more specific. This, I have a table "clients": idClientes, client name and partners_id. The partner_id stores the id of another table "partners": idPartners, namePartner and cnpj. My form stores the data in a third table "export". Thanks for the willingness to help.
– Matheus Madalozzo
Partner id already comes in autocomplete?
– Sam
All right, @Matheusmadalozzo That said, let’s go to the next step: what you want to do is: by selecting a client which shows, in addition to the name, in the field below the value of
parceiros_id
?– Jéf Bueno
@LINQ this, I needed to take the value of partners_id to save it in my third table "export" in "partner_expo". The customer id I already store in this export table.
– Matheus Madalozzo
@Dvd no friend, only the idClientes.
– Matheus Madalozzo
@Matheusmadalozzo See my answer.
– Jéf Bueno
@LINQ excellent, I will try and get back to you as soon as possible.
– Matheus Madalozzo
@LINQ case solved! Excellent help, thank you very much for the solution, availability and agility!
– Matheus Madalozzo