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 3721096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:26:22+00:00 2026-05-19T05:26:22+00:00

On my user inbox from my user messaging system I am building a feature

  • 0

On my user inbox from my user messaging system I am building a feature where a user can make an email message a favourite message.

I have created 2 methods in my messages model. One updates the 0 in the ‘messages’ table, ‘favourite’ column to 1 which would mean the user wants the message to be a favourite. Also the image the user clicks on to make the message a favourite turns from grey to colour.

Then I do this same process again if a user wants to make the message not a favourite. The 1 is updated to a 0 and the image turns greyed out again.

Below is my jquery/javascript that basically does something if the box is checked (image is in colour) and something else if the box is not unchecked (image greyed out).

// favourite check box
    $('input.favourite:checkbox').simpleImageCheck({
  image: '<?php echo base_url()?>images/messages/check.png',
  imageChecked: '<?php echo base_url()?>images/messages/unchecked.png',
  afterCheck: function(isChecked) {
    if (isChecked) {
  //query to db from php to update favourite number to 1
    }
    else (!isChecked)
        {
            //query to db from php to update favourite number to 0
        }
  }
});

What I am trying to figure out is the best way to called my 2 db queries in my model:

public function favourite_checked($message_id)
{
    $username = $this->session->userdata('username');
    return $this->db->query("UPDATE messages SET favourite = 1 WHERE id = $message_id AND to_user = '$username'");    
}

    public function favourite_unchecked($message_id)
{
    $username = $this->session->userdata('username');
    return $this->db->query("UPDATE messages SET favourite = 0 WHERE id = $message_id AND to_user = '$username'");    
}

What would be the best way to do this? Calling a model directly in a view is bad practice isn’t it?

So how could I achieve what I would like to achieve?

Could a controller act as a middle man?

If so how would I even call a controller in a javascript function?

I always appreciate the advice given on here. Thanks in advance

  • 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-05-19T05:26:24+00:00Added an answer on May 19, 2026 at 5:26 am

    In the jQuery, you would use an Ajax get request to a CodeIgniter controller. Say your controller is called users, and your function is called update_favorites. The jQuery call might look like this:

    $.get('http://mysite.com/users/update_favorites/user_id/message_id');
    

    Your controller would then find the URL arguments for user_id and message_id, and load your model with those arguments. The model would make changes to the database.

    Good luck!

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

Sidebar

Related Questions

I want to make an email messaging system like Gmail. I want to have
When using IMAP clients to access your email, the Inbox and any other user-created
Hi I have created a user message page with this plugin. The grid will
I am using zend framework to grab user's email inbox. I got token from
I am trying to build a messaging/chat system. which can store conversation between two
I am creating User messaging functionality from scratch, and am attempting to figure out
Many websites have the concept of sending messages from user to user. When you
I have a named route to the user's inbox, which is maintained by the
I want to parse some emails from a user 's inbox but when I
I'm trying to save email attachment from Google mail account. AFAIK, it can be

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.