- 1
http://forum.php.su/topic.php?forum=71&topic=8913
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+51
http://forum.php.su/topic.php?forum=71&topic=8913
Бывает и такое...
+50
<?php
// ...
if(!empty($_GET['hit']))
{
$tovar2 = mysql_query("select * from `product` where `hit`='1' ORDER BY `weight` DESC, `id` asc ");
}else{
if(!empty($_POST['cena']) && !empty($_POST['meh']) && !empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `new`<'".$_POST['cena']."' and `kat`='".$_POST['meh']."' and `razmer` like '%".$_POST['razmer']."%' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
elseif(!empty($_POST['cena']) && !empty($_POST['meh']) && empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `new`<'".$_POST['cena']."' and `kat`='".$_POST['meh']."' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
elseif(!empty($_POST['cena']) && empty($_POST['meh']) && !empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `new`<'".$_POST['cena']."' and `razmer` like '%".$_POST['razmer']."%' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
elseif(empty($_POST['cena']) && !empty($_POST['meh']) && !empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `kat`='".$_POST['meh']."' and `razmer` like '%".$_POST['razmer']."%' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
elseif(!empty($_POST['cena']) && empty($_POST['meh']) && empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `new`<'".$_POST['cena']."' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
elseif(empty($_POST['cena']) && !empty($_POST['meh']) && empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `kat`='".$_POST['meh']."' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
elseif(empty($_POST['cena']) && empty($_POST['meh']) && !empty($_POST['razmer']))
{
$tovar2 = mysql_query("select * from `product` where `razmer` like '%".$_POST['razmer']."%' ORDER BY `weight` DESC, `id` asc limit $start, $num;");
}
// ...
?>
Make me unsee it!
+46
if (substr($sql,0,6)=='INSERT')
{
$type = 'INSERT';
if ($is_mysql)
$O=mysql_insert_id($connection);
if ($is_ibase)
$O=false;
}
if (substr($sql,0,6)=='UPDATE')
{
$type = 'UPDATE';
if ($is_mysql)
$O = mysql_affected_rows($connection);
if ($is_ibase)
$O = ibase_affected_rows($connection);
}
if (substr($sql,0,7)=='REPLACE')
{
$type = 'REPLACE';
if ($is_mysql)
$O = mysql_affected_rows($connection);
if ($is_ibase)
$O = ibase_affected_rows($connection);
}
if (substr($sql,0,11)=='DELETE FROM')
{
$type = 'DELETE';
if ($is_mysql)
$O = mysql_affected_rows($connection);
if ($is_ibase)
$O = ibase_affected_rows($connection);
}
Как определить возвращаемый результат? Пропарсить строку запроса ($sql)!
+138
function getPage($uri) {
$id = trim(trim($uri, '/'));
if (is_numeric($id)){
$this->page->getPage($id);
} else {
$this->page->getPage('1');
}
}
Вчера сидел в подпитии, писал сайт-визитку. Вот что обнаружил утром
+49
/**
* Used to show configurable product attributes in case when all elements are out-of-stock
*
* "$_product->isSaleable() &&" should be commented out at line #100 (where "container2" block is outputted) in catalog/product/view.phtml
* to make this work
*
* @see Mage_Catalog_Model_Product::isSalable
* @param object $observer
*/
public function onCatalogProductIsSalableAfter($observer)
{
if (Mage::getStoreConfig('amstockstatus/general/outofstock'))
{
$salable = $observer->getSalable();
$stack = debug_backtrace();
foreach ($stack as $object)
{
if (isset($object['file']))
{
if ($object['file'])
{
if ( isset($object['file']) && false !== strpos($object['file'], 'options' . DIRECTORY_SEPARATOR . 'configurable'))
{
$salable->setData('is_salable', true);
}
}
}
}
}
}
Вот такой вот веселый модуль для Magento, одна из возможностей которого - отобразить опции для всех out-of-stock вариантов конфигурируемого товара.
+53
/**
* Магический геттер
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
if ($name == $this->fileName)
return $this->fileName;
}
Magic is here
+38
isset($params) && array_push(
$urlPart,
implode('/',
array_map(
function ($key, $value) {
return $key . '/' . $value;
},
array_keys($params),
array_values($params)
)
)
);
+41
public static function getById( $id )
{
$model = new self;
$data = $model->load();
foreach( $data AS $item ){
if( $item->id == $id ){
return $item;
}
}
return null;
}
Нашел в текущем проекте.
+142
if ($options->get('registrationSetup', 'requireDob')) {
// dob required
Без ДОБ-а не пущу.
+54
public function accuire($array = array()) {
return $this->acquire($array);
}
public function acquire($array = array()) {
Spell-master