gpt4 book ai didi

php - 使用codeigniter在mysql中插入多行: it inserts only one row and in that one row stores only one first character

转载 作者:行者123 更新时间:2023-11-29 16:59:07 27 4
gpt4 key购买 nike

我尝试在 sql 中插入多行。但它仅插入最后一行,并且在该行中仅存储每列的第一个字符。我通过 echo 打印查询,它只显示最后一行,但给出了每列的所有字符。另一件事是我通过单击提交按钮在两个表中插入值。谁能帮忙解决这个问题。

这是 View :

    <form class="" method="POST" enctype="multipart/form-data" action="<?php echo base_url(); ?>dashboard/addnewjobmela" >

<input type="hidden" name="csrfmiddlewaretoken" value="LgVIVf7yFe5bL9k2Rcj9TGLLpgKJX1LkmfiiptEZnN95y9WqKXHk7V4vGixmo6Wd">
<input type="hidden" id="cperson_no" value="1">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Job Mela Title</label>
<input class="form-control" type="text" name="title" required="" id="title">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Job Mela Date</label>
<input class="form-control" type="date" name="date" required="" id="date">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Last Date To Register</label>
<input class="form-control" type="date" name="laastdatetoregister" required="" id="laastdatetoregister">
</div>
</div>
<div class="col-xs-12 col-sm-12 ">
<div class="form-group">
<label>Venue Details</label>
<textarea class="form-control" name="venuedetails" cols="40" rows="2" required="" id="venuedetails"></textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Contact Person</label>
<input class="form-control" type="text" name="contactperson" required="" id="contactperson">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Contact Emailid</label>
<input class="form-control" type="text" name="emailid" required="" id="emailid">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Contact Number</label>
<input class="form-control" type="text" name="contactnumber" required="" id="contactnumber">
</div>
</div>
</div>
<div class="row-fluid" >
<div style="background-color:#d6e9c6 !important;padding:10px"><p class="text-success"><b>Participating Companies</b></p></div>
</div>
<div class="col-xs-12 right" style="margin-top:-40px;margin-bottom: 20px">
<button class="btn btn-success" type="button" onclick="addingcompanies()">Add More</button>
</div>
<div id="companies">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Company Name</label>
<input class="form-control" type="text" name="company" required="" id="company">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Job Title</label>
<input class="form-control" type="text" name="jobtitle" required="" id="jobtitle">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Required Qualification</label>
<?php
echo form_dropdown('qualification', $education,'' ,'required="" class="form-control"');
?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Specialization</label>
<input class="form-control" type="text" name="specialization" required="" id="specialization">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Sector</label>
<input class="form-control" type="text" name="sector" required="" id="sector">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Job Type</label>
<?php
echo form_dropdown('jobtype', $jobtype,'' ,'required="" class="form-control"');
?>
</div>
</div>
<!-- <div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Company Logo</label>
<input class="form-control" type="file" name="picture" accept=".jpeg,.JPEG,.JPG,.jpg,.png,.PNG" required="" id="id_picture">
</div>
</div> -->
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Job Location</label>
<input class="form-control" type="text" name="joblocation" required="" id="joblocation">
</div>
</div>
</div>
</div>

<div class="col-xs-12" style="text-align:center">
<button class="btn btn-success" type="submit" value="Save Profile">Submit</button>
</div>
</form>

Javascript/Jquery 添加“添加更多字段”

<script type="text/javascript">

function addingcompanies()
{
var cperson_no = $('#cperson_no').val();
var j=parseInt(cperson_no)+1;
$('#cperson_no').val(j);
var qualification = '<?php echo str_replace("'", '', preg_replace("/\r|\n/", "", form_dropdown('qualification', $education,'' ,'required="" class="form-control"'))); ?>';
var jobtype = '<?php echo str_replace("'", '', preg_replace("/\r|\n/", "", form_dropdown('jobtype', $jobtype,'' ,'required="" class="form-control"'))); ?>';
$('#companies').append('<div class="row group"><hr/><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Company Name</label> <input class="form-control" type="text" name="company" required="" id="company' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Job Title</label> <input class="form-control" type="text" name="jobtitle" required="" id="jobtitle' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Required Qualification</label> '+ qualification +'</div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Specialization</label> <input class="form-control" type="text" name="specialization" required="" id="specialization' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Sector</label> <input class="form-control" type="text" name="sector" required="" id="sector' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4"> <div class="form-group"> <label>Job Type</label>'+jobtype+' </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Job Location</label> <input class="form-control" type="text" name="joblocation" required="" id="joblocation' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-4 col-md-4 "><button class="btn btn-danger" style="margin-top: 25px; !important;" type="button" onClick="con_grpremove(this)">Remove</button></div></div></div>');


}
function con_grpremove(obj) {
$(obj).closest(".group").remove();
}
</script>

这是 Controller :

public function addnewjob()
{

$this->load->model('dashboard_model');
$result = $this->dashboard_model->addnewjob();
$this->session->msg = "New Job Added Successfully";
redirect('dashboard');

}
public function addnewjobmela()
{

$this->load->model('dashboard_model');
$result = $this->dashboard_model->addnewjobmela();
$this->session->msg = "New Job Mela Added Successfully";
redirect('dashboard');

}

型号:

public function addnewjobmela() {
$data['title'] = $this->input->post('title');
$data['date'] = $this->input->post('date');
$data['lastdate'] = $this->input->post('laastdatetoregister');
$data['venue'] = $this->input->post('venuedetails');
$data['contactperson'] = $this->input->post('contactperson');
$data['emailid'] = $this->input->post('emailid');
$data['contactnumber'] = $this->input->post('contactnumber');
$data['status'] = 1;
$data['id'] = $this->db->insert_id();
print_r($data);
$this->db->insert('jobmelas', $data);
$jobmelaid = $this->db->insert_id();
$jcdata['company'] = $this->input->post('company');
$jcdata['jobtitle'] = $this->input->post('jobtitle');
$jcdata['qualification'] = $this->input->post('qualification');
$jcdata['specialization'] = $this->input->post('specialization');
$jcdata['sector'] = $this->input->post('sector');
$jcdata['jobtype'] = $this->input->post('jobtype');
$this->insCompanies($jobmelaid, $jcdata);
}
public function insCompanies($jobmelaid, $jcdata, $update='') {
if($update == 'update'){
$this->db->query('delete from job_mela_companies where jobmelaid = '.$jobmelaid.'');
}
print_r($jcdata);
for ($i = 0; $i < count($jcdata['company']); $i++) {
$cp_data[] = array(
'jobmelaid' => $jobmelaid,
'company' => $jcdata['company'][$i],
'jobtitle' => $jcdata['jobtitle'][$i],
'qualification' => $jcdata['qualification'][$i],
'specialization' => $jcdata['specialization'][$i],
'jobtype' => $jcdata['jobtype'][$i],
'sector' => $jcdata['sector'][$i]
);

$this->db->insert('job_mela_companies', $cp_data);
}
}

第一个表给出的结果是正确的,但是更多字段的输出如下: enter image description here

最佳答案

尝试下面的数组并从 insCompanies 函数中删除 $cp_data[] = array(....) 。

$cp_data = array(
'jobmelaid' => $jobmelaid,
'company' => $jcdata['company'][$i],
'jobtitle' => $jcdata['jobtitle'][$i],
'qualification' => $jcdata['qualification'][$i],
'specialization' => $jcdata['specialization'][$i],
'jobtype' => $jcdata['jobtype'][$i],
'sector' => $jcdata['sector'][$i]
);

关于php - 使用codeigniter在mysql中插入多行: it inserts only one row and in that one row stores only one first character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52398248/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com