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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:02:22+00:00 2026-05-15T11:02:22+00:00

So the title is a tad ambiguous, but I’ll try and give an example.

  • 0

So the title is a tad ambiguous, but I’ll try and give an example. Basically, I have an ‘awards’ system (similar to that of StackOverflow’s badges) in my PHP/CodeIgniter site, and I want, as soon as an award is earned, a notification to appear to the user.

Now I’m happy to have this appear on the next page load, but, ideally I’d like it to appear as soon as the award is transactioned since my site is mostly Ajax-powered and there may not be page reloads very often.

The way the system works currently, is:

1) If the user does something to trigger the earning of an award, CodeIgniter does this:

$params['user_id'] = $this->tank_auth->get_user_id();
$params['award_id'] = 1; // (I have a database table with different awards in)
$this->awards->award($params);

2) My custom library, $this->awards, runs the award function:

function award($params)
{
    $sql = $this->ci->db->query("INSERT INTO  users_awards (user_id, award_id)
                                 VALUES ('".$params['user_id']."','".$params['award_id']."')
                                 ON DUPLICATE KEY UPDATE duplicate=duplicate+1");

    $awardinfo = $this->ci->db->query("SELECT * FROM awards WHERE id = ".$params['award_id']);

    // If it's the 'first time' the user has gotten the award (e.g. they've earnt it)
    if ($awardinfo->row('duplicate') == 0) {
        $params['title']       = $awardinfo->row('title');
        $params['description'] = $awardinfo->row('description');
        $params['iconpath']    = $awardinfo->row('iconpath');
        $params['percentage']  = $awardinfo->row('percentage');

        return $params;
    }
}

So, it awards the user (and if they’ve earnt it twice, updates a useless duplicate field by one), then checks if it’s the first time they’ve earnt it (so it can alert them of the award). If so, it gets the variables (title of the award, the award description, the path to an icon to display for the award, and finally the percentage of users who have also got this award) and returns them as an array.

So… that’s that. Now I’d like to know, what’s the best way to do this? Currently my Award-giving bit is called from a controller, but I guess if I want this to trigger via Ajax, then the code should be placed in a View file…?

To sum it up: I need the returned award data to appear without a page refresh. What’s the best way of doing this? (I’m already using jQuery on my page).

Thanks very much everybody!

Jack

  • 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-15T11:02:23+00:00Added an answer on May 15, 2026 at 11:02 am

    You need to implement a system of push notification. There are a couple of ways of doing this. You could simply poll for changes:

    setInterval(check_awards, 30000);
    
    function check_awards() {
      $.getJSON('/awards.php', function(result) {
        ...
      });
    }
    

    Every 30 seconds this checks for new awards. If something new is required, the PHP script returns an appropriate JSON object as to the type of award and so on.

    Another way is to use faux push notification:

    $(function() {
      check_awards();
    });
    
    function check_awards() {
      $.ajax({
        url: '/awards.php',
        success: function(data) {
          // update awards
        },
        complete: function() {
          check_awards();
        }
      });
    }
    

    This is sometimes called long-polling. You need to change it so your PHP script doesn’t end until there’s something to return. Whenever the AJAX request returns (due to success or timeout or other error) you start the request again.

    For a detailed example see How to show popup message like in stackoverflow.

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

Sidebar

Related Questions

That title is quite a mouthful. Let me try to be as clear as
Title is the entire question. Can someone give me a reason why this happens?
Title might be a bit confusing, so let me explain. I have a website
Title more or less says it all. Specifically, I've become increasingly annoyed that in
The title might be a bit confusing, basically I'm trying to write up a
title pretty much says it all. I have a website which will only run
Title pretty much says it all. I have a page called login.jsp: <f:view> <html>
Title says what i'm trying to do. I can successfully generate an assembly if
Title says it mostly. I want to add a simple extension method to the
Title field is sealed. Any attempts to update the default value resets the value

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.