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

    +161

    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
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    $searchCondition1 = ''; 
     $searchCondition2 = ''; 
     $searchCondition3 = ''; 
     $flag = false; 
     $sql = 'SELECT f.flight_id,
                   (SELECT city
                    FROM airports
                    WHERE airport_id = f.from) as _from,
                   (SELECT city
                    FROM airports
                    WHERE airport_id = f.to) as _to,
                    f.flight_date as fdate,
                    f.flight_time,
                    f.distance,
                    p.plain_name as plain
            FROM flight f JOIN planes p
                ON f.plain_id = p.plain_id
            WHERE '; 
     $fields = 0; 
     if($_POST['txtSearch']){ 
         if($_POST['txtFrom'] != ''){ 
             $searchCondition1 = " city = '".$_POST['txtFrom']."'"; 
             $flag = true; // set flag to TRUE
             $fields++; 
         }
         if($_POST['txtTo'] != ''){ // if To field is not empty
             $searchCondition2 = " city = '".$_POST['txtTo']."'"; 
             $flag = true;  // set flag to TRUE
             $fields++; 
         }
         if ($_POST['txtDate'] != ''){ // if Date field is not empty
             $searchCondition3 = " DATE(f.flight_date) = '".$_POST['txtDate']."'";
             $fields++; // and inc 
         }
         if($fields == 0){                             
             echo "<br/><div style=\"color:red\">Please, enter at least one filed to search</div>"; 
         }else{ 
             if($searchCondition1 != '' && $searchCondition2 == ''){ 
             $sql .= " f.from IN (SELECT airport_id
                                        FROM airports
                                        WHERE ".$searchCondition1.")"; 
             }
             if($searchCondition1 == '' && $searchCondition2 != ''){ 
                 $sql .= " f.to IN (SELECT airport_id
                                            FROM airports
                                            WHERE ".$searchCondition2.")"; 
             }                                                              
             if($searchCondition1 != '' && $searchCondition2 != ''){ 
                 $sql .= " f.from IN (SELECT airport_id
                                            FROM airports
                                            WHERE ".$searchCondition1.")
                                 AND f.to IN (SELECT airport_id
                                            FROM airports
                                            WHERE ".$searchCondition2.")"; 
             }
             if($searchCondition3 != ''){ 
                 if($flag){ 
                     $sql .= " AND ".$searchCondition3; 
                 }else{
                     $sql .= $searchCondition3; 
                 }
    
             }
             include_once('database.php'); 
             $db = createPDO();
             $result = $db->query($sql);
             echo '<table>
                  <tr>
                    <th>
                        From
                    </th>
                    <th>
                        To
                    </th>
                    <th>
                        Flight Date
                    </th>
                    <th>
                        Flight Time
                    </th>
                    <th>
                        Distance
                    </th>
                    <th>
                        Plane
                    </th>
                    <th>
                        Action
                    </th>
                </tr>'; // create an HTML table with headers
             while($row = $result->fetch()){...}

    Ищем в табличке в зависимости от заполненных полей в форме

    denis90, 22 Октября 2011

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

    +161

    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
    ...
    
      public function getLocations($fresh = 0)
        {
            $tld =& $this->varGet('tld');
            $domain =& $this->varGet('domain');
            
            // if website is viewed via IP
            $noWWWButIP =& $this->varGet('noWWWButIP');
    
            $memCacheKey = 'getLocations';
    
            if (!$fresh) {
                // already fetched and stored in vars?
                if (is_array($this->varGet('arrLocations')))
                    $arrLocations = $this->varGet('arrLocations');
                // lets try fetching from memcache
                else
                    $arrLocations = kd()->lib('kdCache')->get($memCacheKey);
            }
            // regenerate
            unset($arrLocations);
    
            if (!is_array($arrLocations)) {
    ...

    Кэшируем))

    kovel, 21 Октября 2011

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (asdfadfsdf != 1) {
    
    // всякий код
    
    define ('asdfadfsdf',1);
    }

    Типа проверка чтобы "всякий код" исполнялся только 1 раз...

    Tairesh, 21 Октября 2011

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

    +159

    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
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    echo "<center><br><br><form method=\"POST\" action=\"\">
      <select name=\"Data\">";
    $query="SELECT dtDate FROM Energo ORDER BY dtDate Desc"; 
    $res=mssql_query($query) or die("Ошибка запроса!"); 
    while($row = mssql_fetch_array($res))
    {
    echo "
      <option>".$row['dtDate']."</option>";
    }
    echo "</select>
      <input value=\"OK\" type=\"submit\">
    </form><center>";
    
    if(!empty($Data))
    	{
    	echo "<br><br><center><span style=\"font-weight: bold;\">Справка</span><br style=\"font-weight: bold;\">
            <span style=\"font-weight: bold;\">по ..... по состоянию на $Data г.<br><br>";
    		require_once ("tablebuh.lpd");
    		echo "<center><br><br>
    Начальник %Отдел% <img style=\"width: 50%;\"
     alt=\"\" src=\"podpis.gif\" align=\"middle\">
    К***в Н.А.<br><br>
    </center>"; 
    	}
    	
    else
    	{
    	echo "<form method=\"POST\" action=\"\">";
    	echo "<br><br><center><span style=\"font-weight: bold;\">Справка</span><br style=\"font-weight: bold;\">
            <span style=\"font-weight: bold;\">по .... по состоянию на ";
    	$query="SELECT dtDate FROM Energo WHERE id='1'"; 
    	$res=mssql_query($query) or die("Ошибка запроса!"); 
    	while($row = mssql_fetch_array($res)) 
    		{ 
    			$Data=$row['dtDate'];
    			echo $row['dtDate']."<br><br>";
    			require_once ("tablebuh.lpd");
    			echo "</center>"; 
    		}
    	echo "<center><br>
    Начальник %Отдел% <img style=\"width: 50%;\"
     alt=\"\" src=\"podpis.gif\" align=\"middle\">
    К***в Н.А.<br><br>
    ";
    
    //А вот и сам tablebuh.php
    
    <?php
    if(empty($Data))
    {
    require_once ("t2.php");
    }
    else 
    {
    require_once ("t1.php");
    }

    Хах, первый вопрос который задал себе, не пьян ли я был тогда=)
    Самое забавное, в течении 4 месяцев директор не имел никаких претензий по поводу одной и той же информации ежедневно=)

    LazyPiG, 21 Октября 2011

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ( 1 ) { 
     //километровый говнокод 
    } else {
     exit("error");
    }

    Чуть со смеху не умер когда else увидел

    airrussia, 20 Октября 2011

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

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    reset($queue);
          $query = 'SELECT COUNT(*)'
          .' FROM #__datsogallery'
          .' WHERE (0 != 0';
          while (list($key, $cat) = each($queue)) {
            $query .= ' OR catid = '.$cat;
          }
          $query = $query
          .') AND published = 1'
          .' AND approved = 1';
          $db->setQuery($query);
          $result = $db->query();

    Очень возбуждает строка 4.
    Это в официальном релизе компонента com_datsogallery к Joomla 1.5

    airrussia, 20 Октября 2011

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

    +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
    function get_uri()
    {
    	// Path corrector //
    	$path_correct = str_replace("http://","",$_SERVER['REQUEST_URI']);
    	
    	if (($path_correct[strlen($path_correct)-1] != "/") and (!preg_match("#[\.|\?]#i",$path_correct))) {
    	        header("Location: {$_SERVER['REQUEST_URI']}/"); exit;
    	    }
    	// Path parser //
    	$request = str_replace("http://","",$_SERVER['REQUEST_URI']);
    	$params = strpos($request,"?");
    	if ($params>0) { $request = substr($request,0,$params); }
    	@list($ignore,$path) = @explode("/",$request,2);
    	$CRT['PATH'] = @explode("/",$path);
    	if ($CRT['PATH'][count($CRT['PATH'])-1] == "") { unset($CRT['PATH'][count($CRT['PATH'])-1]); }
    	
    	return $CRT['PATH'];
    }

    Пиздец.
    Думаю, какого хрена я отсылаю форму постом, а приходит гет.
    Такое только на пиэйчпи могли написать.

    Nicklasos, 20 Октября 2011

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!empty($query['date_act_start']) && !empty($query['date_act_end'])) {
                    if ($query['date_act_start'] && $query['date_act_end']) {
                        $sphinx->setFilterRange('startdate', $query['date_act_start'], $query['date_act_end']);
                    }
                }

    Вот такая проверка встретилась. Железная =)

    shatzibitten, 20 Октября 2011

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

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $my_query = new WP_Query(array("post_status" => "publish",
                                   "post_type" => "portfolio",
                                   "post_parent" => $post->ID,
                                   "orderby" => "date",
                                   "posts_per_page" => 1));
    
    /*
     * Пиздец конечно, но это видимо самое гениальное, что я мог придумать
     * в 3 часа ночи
     */
    header("Location: ".get_permalink($my_query->posts[0]->ID));

    WordPress.

    varg242, 18 Октября 2011

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

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    ...
    $access = array();  
    $access = file("access.php");  
    ...

    http://forum.php.su/topic.php?forum=33&topic=732

    x34e, 18 Октября 2011

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