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….
Probably Transient API is what you need.