1. PHP / Говнокод #1994

    +150.5

    1. 1
    <a href="#" class="lalalalalala" onclick="$('#frm').submit()">Добавить</a>

    обычный сабмит для веб 2.0 не катит а ни разу ))

    paranoid, 19 Октября 2009

    Комментарии (37)
  2. PHP / Говнокод #1990

    +169.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    function query($sql)
    {
        //DEBUG echo $sql."<br />";
        db::$count++;
        $r = mysql_query($sql);
        if(($this->error = mysql_error()) != "")
            return false;
        else
        {
            $this->error = "";
            return mysql_query($sql);
        }
    }

    Человек долго удивлялся, почему у него в mysql две записи валится при INSERT, а не одна

    striker, 18 Октября 2009

    Комментарии (6)
  3. PHP / Говнокод #1987

    +144.8

    1. 1
    2. 2
    $uploaddir = '../images/';
    $uploadfile1 	= $uploaddir . basename($_FILES['img']['name']);

    все те же индусы

    getme, 16 Октября 2009

    Комментарии (24)
  4. PHP / Говнокод #1986

    +151

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public function __construct()
      {    
        $this->post = $_POST;
        unset($_POST);
      }
      
      public function get($var_name)
      {
        return $this->post[$var_name];
      }

    ещё бы сделали ф-ю
    public function post($var_name)
    {
    return $this->get[$var_name];
    }

    paranoid, 16 Октября 2009

    Комментарии (8)
  5. PHP / Говнокод #1985

    +159.7

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    <?php
    echo test;
    ?>
    
    Денвер отвечает:
    Notice: Use of undefined constant test - assumed 'test' in file.php on line 2
    [Денвер: показать возможную причину ошибки]
    
    Смотрим причину ошибки:
    "Это предупреждение, вероятнее всего, возникает вследствие высокого уровня контроля ошибок в PHP, по умолчанию установленного в Денвере (E_ALL)"

    Скрыл вывод ошибок и профит ;)
    Денвер выращивает быдлоКОТЕРОВ!

    striker, 16 Октября 2009

    Комментарии (4)
  6. PHP / Говнокод #1978

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    $db = JFactory::getDBO();
    		$records = $db->Execute(
                'SELECT DISTINCT(MONTH(publication_date)) ' .
    			' FROM miel_news' .
    			' WHERE `news_type` != \'analytics\' and YEAR(publication_date) = ' . $year .
    			' AND publish=1'.
    			' AND publication_date < \''.date('Y-m-d H:i:s').'\''.
    			' ORDER BY publication_date DESC');
    			
    		if ($records->data){
    			
    			$mm = array('Январь', 'Февраль', 'Март' , 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь');
            	$m_array = array_map('array_shift', $records->data);
            
           		foreach ($m_array as $key => $value){
    	        	$value--;
    	        	$month[] = array('name' => $mm[$value], "id" =>$value+1) ;
    	        }   
    
    	        return 	$month;
    		}

    kovel, 14 Октября 2009

    Комментарии (4)
  7. PHP / Говнокод #1974

    +161.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function read_file($path)
    {if(!is_file($path))return false;
    elseif(!filesize($path))return array();
    elseif($array=file($path))return $array;
    else while(!$array=file($path))sleep(1);
    return $array;}

    интересный способ чтения файла в WR-Counter )))

    inso, 14 Октября 2009

    Комментарии (1)
  8. PHP / Говнокод #1973

    +157

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    <?php
        public function run()
        {
            $db = Registry::get('Db');
    
            $db->transaction(Db_Database::START);
    
            $success = $db->query()->update()
                ->table('forum_topics')
                ->set('PostsCount = PostsCount - 1')
                ->set('LastPostID = ('
                    . $db->query()
                        ->select()->fields('ID')
                        ->table('forum_posts')->order('ID', 1) // DESC
                        ->where('TopicID = %d', $this->post->topic->id)
                        ->limit(1)->compile()->getQuery()
                    . ')')
                ->set('FirstPostID = ('
                    . $db->query()
                        ->select()->fields('ID')
                        ->table('forum_posts')->order('ID')
                        ->where('TopicID = %d', $this->post->topic->id)
                        ->limit(1)->compile()->getQuery()
                    . ')')
                ->where('ID = %d', $this->post->topic->id)
                ->compile()->run()->success()
            && $db->query()->update()
                ->table('forum_cats')
                ->set('PostsCount = PostsCount - 1')
                ->set('LastTopicID = ('
                    . $db->query()
                        ->select()->fields('ID')
                        ->table('forum_topics')->order('LastPostID', 1) // DESC
                        ->where('CatID = %d', $this->post->topic->category->id)
                        ->limit(1)->compile()->getQuery()
                    . ')')
                ->where('ID = %d', $this->post->topic->category->id)
                ->compile()->run()->success()
            && $db->query()->update()
                ->table('forum_posts')
                ->set('Deleted = 1')
                ->where('ID = %d', $this->post->id)
                ->compile()->run()->success();
            $db->transaction($success ? Db_Database::COMMIT : Db_Database::ROLLBACK);
            return $success;
        }

    Вот такая вот жесть бывает. Изменение счетчиков на форуме (денормализация) с использованием альфа-версии кверибилдера. по-моему — устрашающе)

    Shock, 13 Октября 2009

    Комментарии (7)
  9. PHP / Говнокод #1970

    +165.2

    1. 1
    2. 2
    3. 3
    function nik_slashes(&$value)     {
         return (stripslashes($value));
    }

    Коллега сделал свою функцию для удаления слэшей с блек джеком и всем прочим.

    Acid Beast, 13 Октября 2009

    Комментарии (13)
  10. PHP / Говнокод #1968

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    <?php
    /**
     * хелпер подсчитывает кол-во дней между двух дат
     */
    class ********_View_Helper_DateDiff 
    {
    	/**
    	 * из дня, месяца и года формирует время в формате кол-ва дней
    	 * @return integer
    	 */
    	protected function dateToDays($day, $month, $year)
        {
            if ($month > 2) {
                // March = 0, April = 1, ..., December = 9,
                // January = 10, February = 11
                $month -= 3;
            } else {
                $month += 9;
                --$year;
            }
    
            $hb_negativeyear = $year < 0;
            $century         = intval($year / 100);
            $year            = $year % 100;
    
            if ($hb_negativeyear) {
                return intval((14609700 * $century + ($year == 0 ? 1 : 0)) / 400) +
                       intval((1461 * $year + 1) / 4) +
                       intval((153 * $month + 2) / 5) +
                       $day + 1721118;
            } else {
                return intval(146097 * $century / 4) +
                       intval(1461 * $year / 4) +
                       intval((153 * $month + 2) / 5) +
                       $day + 1721119;
            }
        }
    	/**
    	 * высчитывает разницу между двух дат
    	 * @return integer
    	 */
    	public function dateDiff($day1,$month1,$year1,$day2,$month2,$year2) {	
    		$days1 = $this->dateToDays($day1,$month1,$year1);
    		$days2 = $this->dateToDays($day2,$month2,$year2);
    		return ($days1-$days2);
    	}
    }

    кусок самописного расширения ZF.
    про gregoriantojd() люди не знали.

    fatlazyanimal, 12 Октября 2009

    Комментарии (3)