Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8081615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:47:22+00:00 2026-06-05T16:47:22+00:00

My controller get datas from database model, and sends them to view. In view

  • 0

My controller get datas from database model, and sends them to view. In view i do foreach loop to draw divs to each entity. Every single div has a form element to rate its entity.

Controller:

function index(){
    $data['main_content'] = 'list';
    $data['entities'] = $this->database_model->getEntities();
    $this->load->view('template', $data);
}

function postRate(){
    $rate = array(
        'entity_id' => $this->input->post('entity_id'),
        'owner_id' => $this->input->post('owner_id'),
        'value' => $this->input->post('value')
    );
    $this->database_model->persistRate($rate);
    $this->index();
}

Model:

function getEntities(){
    return $this->db->get('entity')->result();
}

function persistRate($rate){
    return $this->db->insert('rate', $rate);
}

View:

<?php foreach($entities as $entity) : ?>
    <div class="entity">
        <?php echo form_open('entities/postRate/', $attr); ?>
        <?php echo form_hidden('entity_id', $entity->id); ?>
        <?php echo form_hidden('owner_id', $userid); ?>
        <?php echo form_hidden('value', 1); ?>
        <?php echo form_submit('submit', '+1'); ?>
        <?php echo form_close(); ?>
    </div>
<?php endforeach; ?>

In this case after rating, entire page will be reloaded but i want to refresh only that div where form was submited. I know javascript or jQuery can do it, ..
UPDATE
.. but i don’t know their logics, how will they know the exact div or the exact (updated) data of actual entity ? Shall i get it from database? i’m just confused with js/jquery/ajax.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:47:24+00:00Added an answer on June 5, 2026 at 4:47 pm

    It is really simple and can be found here: http://api.jquery.com/jQuery.ajax/

    Here is an example:

    $.ajax({
      url: "http://localhost/your_site/controller/method/",
      type: "POST",
      data: {id : 123},
      dataType: "html",
      success: function(data) {
        $('.result').html(data);
      }
    });
    
    <div class="result">
    //YOUR AJAX RESULT WILL BE HERE
    </div>
    

    Your controller method should receive a post variable called id.

    That is a basic example, you really should read the link and learn more about it. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having created my model, view and controller in an attempt to get data from
I have created an entity data model from my database. however in certain areas
I use a foreach in my View to loop over my strongly-typed Model and
Example: I have a view controller and get rid of it. But there's still
As per Ruby on Rails convention, controller names get pluralized while model names are
I'm trying to get a json string back from my controller, that is prefill-values
Let's say that in the controller I get an array of objects from the
I have created a repository that is returning data from my database using Entity
I am trying to populate a dropdown list from database. In my view file
I would like to get POST data sent to page controller in init() function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.