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

  • SEARCH
  • Home
  • 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 8636699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:17:31+00:00 2026-06-12T10:17:31+00:00

I have a small site where I would like to give the ability to

  • 0

I have a small site where I would like to give the ability to users to like each profile with ajax.

So the logic is this, if the use clicks on the like it inserts, but if the person already liked and that’s found in the database delete the record this would be the unlike function.

So the controller looks like this.

public function action_like()
{
    $response = Response::forge();
    $like = Model_Like::forge();
    $like->user_id = Input::post('user_id');
    $like->liked_by = Session::get('sentry_user');
    // find if the user already liked
    $row = Model_Like::find(array($like->user_id, $like->liked_by));
    //if liked remove from database
    if($row):
        $response->body(json_encode(array(
            'status' => 'no',
        )));
        $row->delete();
    else:
        $response->body(json_encode(array(
            'status' => 'yes',
        )));
        $like->save();
    endif;

    return $response;
}

javascript

$('button.like').on('click', function(){
    var likeId = $(this).data('like') 
    valPlus = parseInt($('.like-total').text()) + 1;;
    $.ajax({
        type: "POST",
        url: site_url + 'profile/like/',
        data: {user_id: likeId},
        dataType: "json",
        context: this,
        //async: false,
        beforeSend: function(data) {
            $(this).attr('disabled', 'disabled');
        },
        success: function(data) {
            console.debug(data);
            if(data.status == "yes") {

                $('.like-total').text(valPlus);
            }
        }, 
        complete: function(data) {
            $(this).removeAttr('disabled', 'disabled');
        }
    })
});

So the problem is that the $row always retunrs null, so it is not locating the two id’s and always inserts.

Could please someone give me a hint what I am missing?

  • 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-12T10:17:32+00:00Added an answer on June 12, 2026 at 10:17 am

    I think you have an error in your “Where”. Can you try with this?

    $row = Model_Like::find()->where(array(
        array('user_id', $like->user_id), 
        array('liked_id', $like->liked_by)
    ));
    

    With your “Where” you where searching for the records with ids “$like->user_id” and “$like->liked_by”, not for a single row with both of them.

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

Sidebar

Related Questions

Hey guys, I have developed a small site that i would like to embed
I have a small dynamic site implemented in mod_python . I inherited this, and
I have a database of all countries and cities, I would like to use
I'm working on a small site that I would like to change a little
I am asking a small percentage of users on a site if they would
for my small printing business i would like to have an upload tool on
I am developing a small site using Wordpress.org and would like multiple parents to
I would like to have a responsive image arrangement for backgrounds on a site.
I have an ecommerce site which currently has product URLs like this: http://www.mydomain.com/nike-tshirt/Large http://www.mydomain.com/nike-tshirt/Medium
I have a small web.py Python application that I would like to serve under

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.