简体   繁体   中英

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.

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

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.

my_view fuctuion

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; }

 $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

public function getProductValueById() { $product_id = $this->input->post('product_id'); // return print_r($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

You need to add your email address in which you want to receive emails. Just edit the contact form in admin and add your email under the "Mail" tab.

Apart from this, you also need to contact your hosting to enable the PHP email on the server. Also the "From" email should be an email created in your hosting email like "no-reply@domain.com".

You can also use a plugin to integrate SMTP emails in you site. The plugin can be found here - 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. Once the page load ensure that all of the fields except the following few last:

  • Exclude lines with blank mail-tags from output

  • Use HTML content type

  • File Attachments

  • Mail (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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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