Latest 100 public snipts »
robertbanh's
snipts » mysql
showing 1-3 of 3 snipts for mysql
-
∞ Magento: SQL filter by custom product attrib
<?php // SQL call where custom product attrib 'promo' == 1 $pcollection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') //->addAttributeToFilter('sku',array('like' => '%ABC%')) ->addAttributeToFilter('promo', '1'); foreach($pcollection as $pp) { // method 1 $_promoProduct = $pp->_data; Zend_Debug::dump($_promoProduct); die(); // method 2 $url = $pp->getProductUrl(); $name = $this->htmlEscape($pp->getName()); $img_src = $pp->getThumbnailUrl(325, 215); $price = number_format($pp->getPrice(), 2); // etc }
-
∞ Count Monthly/Yearly Totals in MySQL
SELECT MONTHNAME(createDt) AS month, YEAR(createDt) AS year, COUNT(*) AS total FROM tracking GROUP BY MONTH(createDt), YEAR(createDt) ORDER BY id
-
∞ Use found_rows() in MySQL
// use found_rows() as a sql function mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name -> WHERE id > 100 LIMIT 10; mysql> SELECT FOUND_ROWS();


