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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:36:50+00:00 2026-06-11T13:36:50+00:00

i have a little problem here.. let me introduce… i have a script to

  • 0

i have a little problem here.. let me introduce…

i have a script to create a shortcode.. here’s the script..

//shortcode stock
function stok($atts, $content = null) {  
    extract(shortcode_atts(array(  
        "id" => 'http://net.tutsplus.com'  
    ), $atts));  
    $result = mysql_query("SELECT SUM(quantity) AS value_sum FROM wp_wpsc_cart_contents WHERE prodid = '".$id."'"); 
    $row = mysql_fetch_assoc($result); 
    $stock = '<center><br><b>STOK TERJUAL :</b><div class="nscountdown"><table><thead><tr><td>'.$row['value_sum'].'</td></tr></thead></table></div></center>';
    return $stock;
}  
add_shortcode("stok", "stok");  

as you can see there is a query to sum a column

$result = mysql_query("SELECT SUM(quantity) AS value_sum FROM wp_wpsc_cart_contents WHERE prodid = '".$id."'"); 

Nah.. the problem is.. how to cache the result, because that query make my server load average become spiked…

any solution??

thanks before….

  • 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-11T13:36:51+00:00Added an answer on June 11, 2026 at 1:36 pm

    Probably Transient API is what you need.

    function stok($atts, $content = null) {  
        extract(shortcode_atts(array(  
            "id" => 'http://net.tutsplus.com'  
        ), $atts));  
    
        if ( false === ( $query_cache = get_transient( md5($id) ) ) ) {
            $result = mysql_query("SELECT SUM(quantity) AS value_sum FROM wp_wpsc_cart_contents WHERE prodid = '".$id."'"); 
            $row = mysql_fetch_assoc($result); 
            $stock = '<center><br><b>STOK TERJUAL :</b><div class="nscountdown"><table><thead><tr><td>'.$row['value_sum'].'</td></tr></thead></table></div></center>';
    
            // set one hour lifetime cache with the name of md5($id)
            set_transient( md5($id), $stock, 60*60*1 );     
            return $stock;
        }
        return $query_cache;
    }  
    add_shortcode("stok", "stok");  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem with Jquery getJSON function. my json here { entries:
I have a little problem with javascript form submit issue, here is the script
So, here is my little problem. Let's say I have a list of buckets
I need a little push in the right direction. Here's my problem: I have
I'm having a little problem here! I have discovered the following as being the
I have a little problem here.. I have a form and I write it
I still have a little problem grasping the concept of pure OOD. Let's say
I have a litte problem here. I want to join twice from the same
I'm new around here and i have a little problems with a C# application.
I have little problem with a replacement of a little part in an url.

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.