简体   繁体   English

如何使用 Codeigniter 中的 id 从 ajax 获取所有记录结果

[英]How to get all records result from ajax using a id in Codeigniter

I need a experience guidance about get the result database using ajax in Codeigniter.我需要有关在 Codeigniter 中使用 ajax 获取结果数据库的经验指导。

Actually I am getting the images using category_id from a table, the imortant thing is that the category_id can be more then one because we have multiple category_id in our table实际上我是使用表中的 category_id 获取图像,重要的是 category_id 可以不止一个,因为我们的表中有多个 category_id

my approch was that i am send the category_id using select and that id is sending through ajax and then getting the result but i am getting the result in array i am not understanding how to display that data in my view.我的方法是我使用 select 发送 category_id 并且该 id 是通过 ajax 发送然后得到结果,但是我在数组中得到结果我不明白如何在我的视图中显示该数据。

my_view fuctuion my_view 函数

function productData(product_id) { var product_id = $("#product_name").val(); function productData(product_id) { var product_id = $("#product_name").val();

 $.ajax({ url: base_url + 'products/getProductValueById', type: 'post', data: {product_id: product_id}, dataType: 'json', success:function(response) { console.log(response); } // /success }); // /ajax function to fetch the product data }

my database query我的数据库查询

public function getProductDataByCategoryId($id = null) { if(;$id) { return false;公共 function getProductDataByCategoryId($id = null) { if(;$id) { return false; } }

 $sql = "SELECT products.image FROM products WHERE products.category_id = $id"; $query = $this->db->query($sql, array($id)); return $query->result_array(); }

my model function from where i send and receive the data我的 model function 从哪里发送和接收数据

public function getProductValueById() { $product_id = $this->input->post('product_id');公共 function getProductValueById() { $product_id = $this->input->post('product_id'); // return print_r($product_id); // 返回 print_r($product_id); if($product_id) { $product_data = $this->model_products->getProductDataByCategoryId($product_id); if($product_id) { $product_data = $this->model_products->getProductDataByCategoryId($product_id);

 // print_r($product_data); echo json_encode($product_data); } }

You could actually initialize contact form in all the templates using shortcode您实际上可以使用简码在所有模板中初始化联系表单

<?php echo do_shortcode( '[contact-form-7 id=”1" title=”Contact form 1"]' ); ?>

Like this example像这个例子

`<div class=”row”>
  <div class=”col”>
   <?php echo do_shortcode('[text* your-name placeholder”Name”]'); ?>
  </div>
</div>
`

Or you can add html in contact form plugin like this and use short code in templates conatct form page或者您可以像这样在联系表单插件中添加 html 并在模板联系表单页面中使用短代码

You need to add your email address in which you want to receive emails.您需要添加您想要接收电子邮件的 email 地址。 Just edit the contact form in admin and add your email under the "Mail" tab.只需在管理员中编辑联系表格,然后在“邮件”选项卡下添加您的 email。

Apart from this, you also need to contact your hosting to enable the PHP email on the server.除此之外,您还需要联系您的主机以在服务器上启用 PHP email。 Also the "From" email should be an email created in your hosting email like "no-reply@domain.com".此外,“发件人”email 应该是在您的托管 email 中创建的 email,例如“no-reply@domain.com”。

You can also use a plugin to integrate SMTP emails in you site.您还可以使用插件在您的站点中集成 SMTP 电子邮件。 The plugin can be found here - https://wordpress.org/plugins/wp-smtp/该插件可以在这里找到 - https://wordpress.org/plugins/wp-smtp/

Once you create your email form via the Contact 7 plugin, click on the "Edit" button then check the "Mail" tab which is the second one.通过 Contact 7 插件创建 email 表单后,单击“编辑”按钮,然后检查第二个“邮件”选项卡。 Once the page load ensure that all of the fields except the following few last:页面加载后,请确保除以下几个字段之外的所有字段都在最后:

  • Exclude lines with blank mail-tags from output从 output 中排除带有空白邮件标签的行

  • Use HTML content type使用 HTML 内容类型

  • File Attachments文件附件

  • Mail (2)邮件 (2)

You can configure these options as well, however they are only optional.您也可以配置这些选项,但它们只是可选的。 Also ensure that the fields for " To " and " From " are filed with an email that actually exist.还要确保“ To ”和“ From ”字段与实际存在的 email 一起归档。

If you are still unable to send emails the best option will be to contact your web hosting provider as they will be able to review the server log for outgoing emails and provide more detailed information on the experienced issue.如果您仍然无法发送电子邮件,最好的选择是联系您的 web 托管服务提供商,因为他们将能够查看外发电子邮件的服务器日志并提供有关遇到问题的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM