- 1
- 2
- 3
- 4
- 5
if ($w>$n) {
print round(100/($w/$n))
} else if ($n>$w) {
print round(100/($n/$w))
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+3
if ($w>$n) {
print round(100/($w/$n))
} else if ($n>$w) {
print round(100/($n/$w))
}
процентное соотношение между $w и $n
+1001
if ($captcha_url != '' && 1 == 1) {
//echo $html;
require('antigate.php');
Интересно, зачем потребовалось единицы сравнивать
+141
switch($op){
case 'main': IndexNewszMain();
break;
// ......
case 'savepost':
if(CommentsEditPostSave(SafeEnv($_GET['newsz'], 11, int), 'newsz_comments')){
break;
}
// .....
// //
default: IndexNewszMain();
}
Роутинг из модуля одной русской CMS
+143
$style = "{ width: 100%; ";
if ($count % 2 == 0) {
$style .= 'background: lightgrey;';
}
$style .= "}";
+144
if ( (($i%3) == 0) || ($i==$cnt) ) { // $i mod 3
if ($i == 6) {
Без комментариев.
+145
if ($test_domain->num_rows or true )
Обычная проверка на количество строк в запросе... Видимо, не всегда попадало в условие, и автор решил добавить or)
+142
<?php
public
function filter()
{
$manufacturers = Manufacturers::all();
$products = Products::where('category', '=', Input::get('category'))->get();
if (Input::get('size') != 'notselected')
{
$size = Input::get('size');
}
if (Input::get('category') == 3)
{
if (Input::get('type') != 'notselected')
{
$products = Products::where('category', '=', Input::get('category'))->where('type', '=', Input::get('type'))->get();
}
}
if (Input::get('manufacturer') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('manufacturer', '=', Input::get('manufacturer'))->get();
}
if (Input::get('min') != 0 and Input::get('max') != 0)
{
$products = Products::where('category', '=', Input::get('category'))->whereBetween('price', array(
Input::get('min') ,
Input::get('max')
))->get();
if (Input::get('size') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('size', 'LIKE', "%$size%")->whereBetween('price', array(
Input::get('min') ,
Input::get('max')
))->get();
}
else
{
$products = Products::where('category', '=', Input::get('category'))->whereBetween('price', array(
Input::get('min') ,
Input::get('max')
))->get();
}
if (Input::get('manufacturer') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('manufacturer', '=', Input::get('manufacturer'))->whereBetween('price', array(
Input::get('min') ,
Input::get('max')
))->get();
}
else
{
$products = Products::where('category', '=', Input::get('category'))->whereBetween('price', array(
Input::get('min') ,
Input::get('max')
))->get();
}
}
if (Input::get('minim') != 0)
{
$products = Products::where('category', '=', Input::get('category'))->where('price', '<', Input::get('minim'))->get();
if (Input::get('size') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('size', 'LIKE', "%$size%")->where('price', '<', Input::get('minim'))->get();
}
else
{
$products = Products::where('category', '=', Input::get('category'))->where('price', '<', Input::get('minim'))->get();
}
if (Input::get('manufacturer') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('manufacturer', '=', Input::get('manufacturer'))->where('price', '<', Input::get('minim'))->get();
}
else
{
$products = Products::where('category', '=', Input::get('category'))->where('price', '<', Input::get('minim'))->get();
}
}
if (Input::get('maxim') != 0)
{
$products = Products::where('category', '=', Input::get('category'))->where('price', '>', Input::get('maxim'))->get();
if (Input::get('size') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('size', 'LIKE', "%$size%")->where('price', '>', Input::get('maxim'))->get();
}
else
{
$products = Products::where('category', '=', Input::get('category'))->where('price', '>', Input::get('maxim'))->get();
}
if (Input::get('manufacturer') != "notselected")
{
$products = Products::where('category', '=', Input::get('category'))->where('manufacturer', '=', Input::get('manufacturer'))->where('price', '>', Input::get('maxim'))->get();
}
Вот так был реализован фильтр интернет-магазина. Не ну а хули?
+143
if (strlen($this->post['Name']) >= 3) {
$p = preg_split('/\s+/', $name) + [' ', ' '];
sort($p);
$permutation = [$p[0], $p[1], $p[2], $p[0], $p[1], $p[0], $p[2], $p[1], $p[0]];
$name = join(' ', $permutation);
$list = Model_Students::searchStudentsByName($name, $facultyID, $gradeID, $groupID);
}
С ребятами запилили полнотекстовый поиск фио. Функция из модели — вызов MySQL процедуры.
Реалия простая — MySQL не умеет в split, не умеет в переменное количество параметров, не умеет в нечёткий поиск. Выкручиваемся как можем.
+144
if($data_user['status']==2){
echo "<center><table class='wdt green-header'><tr><td align='left'><a href='/adm_panel/index.php'><font color='#fff'><b><div class='title'>Админ панель</td></b></font></a></center></div>";
}
if($data_user['status']==3){
echo "<center><table class='wdt green-header'><tr><td align='left'><a href='/adm_panel/index.php'><font color='#fff'><b><div class='title'>Админ панель</td></b></font></a></center></div>";
}
if($data_user['status']==4){
echo "<center><table class='wdt green-header'><tr><td align='left'><a href='/adm_panel/index.php'><font color='#fff'><b><div class='title'>Админ панель</td></b></font></a></center></div>";
}
if($data_user['status']==5){
echo "<center><table class='wdt green-header'><tr><td align='left'><a href='/adm_panel/index.php'><font color='#fff'><b><div class='title'>Админ панель</td></b></font></a></center></div>";
}
Пожалуй, это самый божественный код, который я когда либо видел. Похлопаем кодеру, написавшему этот код(не я, двиг из паблика):D
+144
function deadlineDatecompare(AdminOrder $a, AdminOrder $b) {
$nullresult = nullcompare($a, $b);
if ($nullresult !== null) return $nullresult;
//В 2999 году заменить
$aDate = new DateTime('2999-12-31');
$bDate = new DateTime('2999-12-31');
foreach ($a->get_existingitems() as $item) {
foreach ($item->get_deadlines(true) as $deadline) {
if (!($deadline->completed || $deadline->missed)) {
$aDate = min($deadline->deadlineDateWithTime, $aDate);
}
}
}
foreach ($b->get_existingitems() as $item) {
foreach ($item->get_deadlines(true) as $deadline) {
if (!($deadline->completed || $deadline->missed)) {
$bDate = min($deadline->deadlineDateWithTime, $bDate);
}
}
}
//сравниваем через timestamp для производительности
$aTimestamp = $aDate->getTimestamp();
$bTimestamp = $bDate->getTimestamp();
if ($aTimestamp > $bTimestamp) {
//дата позже, значит выше заказ ставим
return -1;
} elseif ($aTimestamp < $bTimestamp) {
return 1;
} else return 0;
}
Новый проект