我正在尝试将数组作为参数传递给我的存储过程。但我没有得到预期的结果。
我试着从点击按钮的视图向控制器发送电子邮件和id的列表,然后我试着通过将该列表作为参数传递给我的存储过程从数据库中获取数据。
这是我的密码:
查看:
<form action="<?= base_url('certificate/sendMail') ?>" method="post">
<table id="example1" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>Mail</th>
</tr>
</thead>
<tfoot>
<tr>
<th style="text-align: center;">
<input type="submit" name="submit" value="Send" class="send btn btn-primary btn-xs" disabled="" />
</th>
</tr>
</tfoot>
<tbody>
<tr>
<td style="text-align: center;">
<input type="checkbox" class="checkbox" name="sendMail[]" value="<?= $certify->landlord_main_email; ?>">
</td>
</tr>
</tbody>
</table>
</form>
在这里,我得到的电子邮件和身份证清单通过复选框。
控制器:
public function sendMail($certID)
{
# code...
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['sendMail'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['sendMail'] as $selected){
//echo $selected."</br>";
}
}
}
$result['certMails'] = $this->c->getCertificateByEmail($certID);
$email_to = $this->input->post('sendMail[]');
$body = $this->load->view('Emails/emailAll', '', true);
}
在这里,我试图获得数据,并将其发送到电子邮件模板视图。
型号:
public function getCertificateByEmail($certID)
{
# code...
$query = $this->db->query("call getCertificateByEmail($certID)");
if ($query) {
$data = $query->result();
$query->next_result();
$query->free_result();
return $data;
} else {
return false;
}
}
存储过程:
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `Certificate_By_Email`(IN `certID` INT)
BEGIN
SELECT `cert_id`, `cert_user_id`, `cert_landlord_id`,
tbl_landlord.landlord_id, tbl_landlord.landlord_main_email,
`cert_property_id`, tbl_property.property_code,
tbl_property.property_city, tbl_property.property_cluster,
tbl_cluster.cluster_name, `cert_status`, `cert_number`,
tbl_certificates.certificate_name, `cert_issue_date`,
`cert_expiry_date`, `cert_duration`, `cert_updated_date`,
`cert_remarks`, `cert_notes`
FROM `tbl_certificate_details`
LEFT OUTER JOIN tbl_landlord ON tbl_certificate_details.cert_landlord_id = tbl_landlord.landlord_id
LEFT OUTER JOIN tbl_property ON tbl_certificate_details.cert_property_id = tbl_property.property_id
LEFT OUTER JOIN tbl_certificates ON tbl_certificate_details.certificate_id = tbl_certificates.certificate_id
LEFT OUTER JOIN tbl_cluster ON tbl_property.property_cluster = tbl_cluster.cluster_id
LEFT OUTER JOIN tbl_area ON tbl_property.property_area = tbl_area.area_name
WHERE FIND_IN_SET(cert_id, certID);
END$$
DELIMITER ;
欢迎任何帮助,提前谢谢。
1条答案
按热度按时间lnxxn5zx1#
我看不见
$certID
定义于sendMail()
. 如果你把它打印出来会有什么价值?我敢肯定你只是用
$this->input->post('sendMail');
而不是$this->input->post('sendMail[]');
获取阵列您是否确认您的(不安全的)sql调用可以使用自定义值?如果是,请确保传递的值正确
尝试调试和故障排除,您可能会找到原因。