我想在选择框时显示客户信息。我在视图中输入选择输入,当我选择从选择框中选择任何客户时,在下面列出了他的财产信息。我该怎么办?
我在下面显示我的代码:
状态表:
CREATE TABLE `estate` (
`estateId` int(11) NOT NULL AUTO_INCREMENT,
`estateType` int(11) DEFAULT NULL COMMENT 'mülk türü ev, villa v.b',
`estateCentare` varchar(6) COLLATE utf8_bin DEFAULT NULL,
`estateRoom` varchar(2) COLLATE utf8_bin DEFAULT NULL COMMENT 'adet',
`estateSalon` varchar(2) COLLATE utf8_bin DEFAULT NULL COMMENT 'adet',
`estateBathroom` varchar(2) COLLATE utf8_bin DEFAULT NULL COMMENT 'adet',
`estateHeating` int(11) DEFAULT NULL COMMENT 'ısıtma turu tablosu',
`estateCity` int(11) DEFAULT NULL COMMENT 'city Tablosu',
`estateAddress` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`estateCoord` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`estateGarden` tinyint(1) DEFAULT NULL COMMENT 'evin bahçesi var yok',
`estateBalcony` tinyint(1) DEFAULT NULL COMMENT 'balkon adet',
`estatePackage` varchar(255) COLLATE utf8_bin DEFAULT NULL,
`estatePackageDate` datetime DEFAULT NULL,
`estatePackageUser` int(11) DEFAULT NULL,
`estateCreateDate` datetime DEFAULT NULL,
`estateCreateUser` int(11) DEFAULT NULL,
`estateEditDate` datetime DEFAULT NULL,
`estateEditUser` int(11) DEFAULT NULL,
`estateDue` decimal(5,0) DEFAULT NULL,
PRIMARY KEY (`estateId`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
cosId在列出其遗产信息时将等于estateId。
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Property extends CI_Controller {
public function index()
{
$this->lang->load('content', $this->session->userdata('people_lang'));
$viewData = new stdClass();
$viewData->customers = $this->db->get("customer")->result();
$this->load->view('property', $viewData);
}
}
?>
查看:
<section class="panel">
<header class="panel-heading">
PROPERTY / ESTATE
<span class="tools pull-right">
<a href="javascript:;" class="fa fa-chevron-down"></a>
<a href="javascript:;" class="fa fa-times"></a>
</span>
</header>
<div class="panel-body">
<h5>Property / Estate Management</h5>
<div class="form-group" hidden>
<label class="col-sm-2 col-sm-2 control-label">User Who Add:</label>
<div class="col-sm-10">
<input type="text" name="docFileCreateUser" class="form-control" value="<?php echo $this->session->userdata("people_id"); ?>" readonly>
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<h5 class=""><i class="fas fa-handshake"></i> Choose Customer:</h5>
<select class="js-example-basic-single" name="docFileDocType" required="required">
<option value="" readonly>Select</option>
<?php
foreach($customers as $customer){ if ($customer->cosStatus == 1) { ?>
<option value="<?php echo $customer->cusId; ?>"><?php echo $customer->cosCode; ?> <?php echo $customer->cosName. '' .$customer->cosSurname ?></option>
<?php } }?>
</select>
</div>
</div>
</div>
<div class="panel-body">
<div class="adv-table">
<h4><?php echo $customer->cosName.' '.$customer->cosSurname;?> | Information of Current Payments:</h4>
<div class="panel-body">
<section id="no-more-tables">
<table class="table table-bordered table-striped table-condensed cf" id="dynamic-table">
<thead class="cf">
<tr>
<th>File ID</th>
<th>Customer Code</th>
<th>Name Surname</th>
<th>File Type</th>
<th>Description</th>
<th>Create Date</th>
<th>File</th>
</tr>
</thead>
<tbody>
<?php
foreach($documents as $docs){ if(($customer->cusId) == ($docs->docFileCusId)){ ?>
<tr>
<td data-title="File ID"><?php echo $docs->docFileId; ?></</td>
<td data-title="Customer Code"><?php echo $customer->cosCode; ?></td>
<td data-title="Name Surname"><?php echo $customer->cosName.' '.$customer->cosSurname; ?></</td>
<td data-title="File Type"><?php echo $docs->docFileDocType; ?></td>
<td data-title="Description"><?php echo $docs->docFileDesc; ?></td>
<td data-title="Create Date"><?php echo $docs->docFileCreateDate; ?></</td>
<td data-title="File"><a href="<?php echo base_url().'upload/file/customer/'.$docs->docFileDirectory;?>" download><?php echo $docs->docFileDirectory; ?></a> <i class="fa fa-download"></i></td>
</tr>
<?php } } ?>
</tbody>
</table>
</section>
</div>
</div>
</div>
</section>
答案 0 :(得分:1)
在选择器上使用OnChange函数:
<select onChange="showInfo(this.value);" class="js-example-basic-single" name="docFileDocType" required="required">
JavaScript:
function showInfo(str){
$.ajax({
type: "POST",
data: { id: str },
url: "<?=base_url('property/getInfo');?>",
success: function(data) {
$('#divInfo').html(data);
}
});
}
控制器(getInfo):
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Property extends CI_Controller {
public function index(){
$this->lang->load('content', $this->session->userdata('people_lang'));
$viewData = new stdClass();
$viewData->customers = $this->db->get("customer")->result();
$this->load->view('property', $viewData);
}
public function getInfo(){
$id = $this->input->post('id');
$viewData->estate = $this->db->get_where("estate",['estateId'=>$id])->result();
$this->load->view('getInfo', $viewData);
}
}
?>
查看(getInfo)“小零件”。
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
<th>Column 6</th>
<th>Column 7</th>
<th>Column 8</th>
<th>Column 9</th>
<th>Column 10</th>
<th>Column 11</th>
<th>Column 12</th>
<th>Column 13</th>
<th>Column 14</th>
<th>Column 15</th>
<th>Column 16</th>
<th>Column 17</th>
<th>Column 18</th>
<th>Column 19</th>
<th>Column 20</th>
</tr>
<?php foreach($estates as $estate){?>
<tr>
<td><?php echo $estate->estateId; ?></</td>
<td><?php echo $estate->estateType; ?></</td>
<td><?php echo $estate->estateCentare; ?></</td>
<td><?php echo $estate->estateRoom; ?></</td>
<td><?php echo $estate->estateSalon; ?></</td>
<td><?php echo $estate->estateBathroom; ?></</td>
<td><?php echo $estate->estateHeating; ?></</td>
<td><?php echo $estate->estateCity; ?></</td>
<td><?php echo $estate->estateAddress; ?></</td>
<td><?php echo $estate->estateCoord; ?></</td>
<td><?php echo $estate->estateGarden; ?></</td>
<td><?php echo $estate->estateBalcony; ?></</td>
<td><?php echo $estate->estatePackage; ?></</td>
<td><?php echo $estate->estatePackageDate; ?></</td>
<td><?php echo $estate->estatePackageUser; ?></</td>
<td><?php echo $estate->estateCreateDate; ?></</td>
<td><?php echo $estate->estateCreateUser; ?></</td>
<td><?php echo $estate->estateEditDate; ?></</td>
<td><?php echo $estate->estateEditUser; ?></</td>
<td><?php echo $estate->estateDue; ?></</td>
</tr>
<?php } ?>
新视图(属性):
<section class="panel">
<header class="panel-heading">
PROPERTY / ESTATE
<span class="tools pull-right">
<a href="javascript:;" class="fa fa-chevron-down"></a>
<a href="javascript:;" class="fa fa-times"></a>
</span>
</header>
<div class="panel-body">
<h5>Property / Estate Management</h5>
<div class="form-group" hidden>
<label class="col-sm-2 col-sm-2 control-label">User Who Add:</label>
<div class="col-sm-10">
<input type="text" name="docFileCreateUser" class="form-control" value="<?php echo $this->session->userdata("people_id"); ?>" readonly>
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<h5 class=""><i class="fas fa-handshake"></i> Choose Customer:</h5>
<select class="js-example-basic-single" name="docFileDocType" required="required">
<option value="" readonly>Select</option>
<?php
foreach($customers as $customer){ if ($customer->cosStatus == 1) { ?>
<option value="<?php echo $customer->cusId; ?>"><?php echo $customer->cosCode; ?> <?php echo $customer->cosName. '' .$customer->cosSurname ?></option>
<?php } }?>
</select>
</div>
</div>
</div>
<div class="panel-body">
<div class="adv-table">
<h4><?php echo $customer->cosName.' '.$customer->cosSurname;?> | Information of Current Payments:</h4>
<div class="panel-body">
<section id="no-more-tables">
<table class="table table-bordered table-striped table-condensed cf" id="dynamic-table">
<thead class="cf">
<tr>
<th>File ID</th>
<th>Customer Code</th>
<th>Name Surname</th>
<th>File Type</th>
<th>Description</th>
<th>Create Date</th>
<th>File</th>
</tr>
</thead>
<tbody>
<?php
foreach($documents as $docs){ if(($customer->cusId) == ($docs->docFileCusId)){ ?>
<tr>
<td data-title="File ID"><?php echo $docs->docFileId; ?></</td>
<td data-title="Customer Code"><?php echo $customer->cosCode; ?></td>
<td data-title="Name Surname"><?php echo $customer->cosName.' '.$customer->cosSurname; ?></</td>
<td data-title="File Type"><?php echo $docs->docFileDocType; ?></td>
<td data-title="Description"><?php echo $docs->docFileDesc; ?></td>
<td data-title="Create Date"><?php echo $docs->docFileCreateDate; ?></</td>
<td data-title="File"><a href="<?php echo base_url().'upload/file/customer/'.$docs->docFileDirectory;?>" download><?php echo $docs->docFileDirectory; ?></a> <i class="fa fa-download"></i></td>
</tr>
<?php } } ?>
</tbody>
</table>
</section>
</div>
</div>
</div>
<div id="divInfo"></div>
</section>
希望这会有所帮助。