mysql中的行转列
//查看当前商品库存
function checkProductStock($product_id){ global $wpdb; $sql="SELECT post_id,max(if((meta_key = '_stock_status'),meta_value,'')) AS stock_status,//此方法的作用 max(if((meta_key = '_manage_stock'),meta_value,'')) AS manage_stock, max(if((meta_key = '_stock'),meta_value,'')) AS stock from wp_postmeta WHERE post_id=".$product_id; $productStock=$wpdb->get_row($sql, ARRAY_A); $warehome=0; if(isset($productStock['stock_status']) && $productStock['stock_status']=='instock'){ if(empty($productStock['manage_stock']) || $productStock['manage_stock']=='no'){ $warehome=9999; } if(isset($productStock['manage_stock']) && $productStock['manage_stock']=='yes' && isset($productStock['stock']) && $productStock['stock']>0){ $warehome=$productStock['stock']; } } return $warehome; }