- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
<?php
switch(1==1) {
case true;
// ...
break;
case false;
// ...
break;
}
?>
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+142
<?php
switch(1==1) {
case true;
// ...
break;
case false;
// ...
break;
}
?>
Аналог конструкции if-else...
+65
$needDied = $this->battle_data['type'] == 104 ? true : false;
+50
// $conn - mysqli_object
$query = "insert into orders values
('0', '".$customerid."', '".$_SESSION['total_price']."',
'".$date."', '".PARTIAL."', '".$ship_name."',
'".$ship_address."', '".$ship_city."',
'".$ship_state."', '".$ship_zip."',
'".$ship_phone."', '".$ship_mail."')";
$result = $conn->query($query) ;
if (!$result) {
return false;
}
//amount - float
$query = "select orderid from orders where
customerid = '".$customerid."' and
amount > (".$_SESSION['total_price']."-.001) and
amount < (".$_SESSION['total_price']."+.001) and
date = '".$date."' and
order_status = 'PARTIAL' and
ship_name = '".$ship_name."' and
ship_address = '".$ship_address."' and
ship_city = '".$ship_city."' and
ship_state = '".$ship_state."' and
ship_zip = '".$ship_zip."' and
ship_country = '".$ship_country."'";
$result = $conn->query($query);
if ($result->num_rows > 0) {
$order = $result->fetch_object();
$orderid = $order->orderid;
} else {
return false;
}
Источник: Люк Веллинг и Лора Томсон: Разработка веб-приложений с помощью PHP и MySQL(4 издание стр 594)
Как выдрать last_insert_id? Очень просто: нужно составить запрос на select вставленного orderid с указанием всех вставленных значений в поля, а для флоата указать на всякий случай интервал, и только тогда можно из выборки извлечь вставленный id
ps: констатна PARTIAL нигде не задаётся=)
−35
// For the probably_koi8_locales we have to look. the standard says
// these are 8859-5, but almost all Russian users use KOI8-R and
// incorrectly set $LANG to ru_RU. We'll check tolower() to see what
// it thinks ru_RU means.
// If you read the history, it seems that many Russians blame ISO and
// Perestroika for the confusion.
...
static QTextCodec * ru_RU_hack(const char * i) {
QTextCodec * ru_RU_codec = 0;
#if !defined(QT_NO_SETLOCALE)
QByteArray origlocale(setlocale(LC_CTYPE, i));
#else
QByteArray origlocale(i);
#endif
// unicode koi8r latin5 name
// 0x044E 0xC0 0xEE CYRILLIC SMALL LETTER YU
// 0x042E 0xE0 0xCE CYRILLIC CAPITAL LETTER YU
int latin5 = tolower(0xCE);
int koi8r = tolower(0xE0);
if (koi8r == 0xC0 && latin5 != 0xEE) {
ru_RU_codec = QTextCodec::codecForName("KOI8-R");
} else if (koi8r != 0xC0 && latin5 == 0xEE) {
ru_RU_codec = QTextCodec::codecForName("ISO 8859-5");
} else {
// something else again... let's assume... *throws dice*
ru_RU_codec = QTextCodec::codecForName("KOI8-R");
qWarning("QTextCodec: Using KOI8-R, probe failed (%02x %02x %s)",
koi8r, latin5, i);
}
#if !defined(QT_NO_SETLOCALE)
setlocale(LC_CTYPE, origlocale);
#endif
return ru_RU_codec;
}
Снова Qt. На этот раз src/corelib/codecs/qtextcodec.cpp и борьба бобра с ослом русских с буржуинскими стандартами ISO.
+108
public sbyte GetSByte(int i)
{
IMySqlValue v = GetFieldValue(i, false);
if (v is MySqlByte)
return ((MySqlByte)v).Value;
return ((MySqlByte)v).Value;
}
Вытащил это "чудо" когда ковырялся в сырцах MySQL .NET Connector-а
+127
static char[] decToBin(int n)
{
byte size = sizeof(int) * 8;
char[] result = new char[size];
for (int i = 0; i < size; i++)
{
result[size - i - 1] = (((n >> i) & 1).ToString().ToCharArray()[0]);
}
return result;
}
Плохо пахнущий транслятор непосредственно в дополнительный код.
+141
function toArray($xml) {
$xml = simplexml_load_string($xml);
$json = json_encode($xml);
return json_decode($json,TRUE);
}
Но зачем?!
+148
var isScheduledRadio = $('#ContentPlaceHolder1_FormView1_ctl04_ctl00___IsScheduled_RadioButtonList1_0')[0],
isSitnGoRadio = $('#ContentPlaceHolder1_FormView1_ctl04_ctl00___IsScheduled_RadioButtonList1_1')[0],
startDateTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl07___StartDate_TextBox1')[0],
minPlayersTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl14___MinPlayers_TextBox1')[0],
maxPlayersTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl15___MaxPlayers_TextBox1')[0],
maxPlayersRequiredValidator = $('#ContentPlaceHolder1_FormView1_ctl04_ctl15___MaxPlayers_RequiredFieldValidator1')[0],
maxPlayersRow = $('#ContentPlaceHolder1_FormView1_ctl04_ctl15___MaxPlayers_TextBox1')
.parent()
.parent()[0],
endDateTextBox = $('#ContentPlaceHolder1_FormView1_ctl04_ctl08___EndDate_TextBox1')[0],
endDateRequiredValidator = $('#ContentPlaceHolder1_FormView1_ctl04_ctl08___EndDate_RequiredFieldValidator1')[0],
endDateRow = $('#ContentPlaceHolder1_FormView1_ctl04_ctl08___EndDate_TextBox1')
.parent()
.parent()[0],
Увидел такой код с сорцах ASP.Net страницы
+160
function changeFilter(event) {
if (parseInt(event.newValue) < 1000) {
api.Msg.showErr("Укажите год!");
}
}
Обработчик onchange поля "Год"
+70
function navigationblock() {
$lettersarr=array();
function _strtolower($string)
{
$small = array('а','б','в','г','д','е','ё','ж','з','и','й',
'к','л','м','н','о','п','р','с','т','у','ф',
'х','ч','ц','ш','щ','э','ю','я','ы','ъ','ь',
'э', 'ю', 'я');
$large = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й',
'К','Л','М','Н','О','П','Р','С','Т','У','Ф',
'Х','Ч','Ц','Ш','Щ','Э','Ю','Я','Ы','Ъ','Ь',
'Э', 'Ю', 'Я');
return str_replace($large, $small, $string);
}
function _strtoupper($string)
{
$small = array('а','б','в','г','д','е','ё','ж','з','и','й',
'к','л','м','н','о','п','р','с','т','у','ф',
'х','ч','ц','ш','щ','э','ю','я','ы','ъ','ь',
'э', 'ю', 'я');
$large = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й',
'К','Л','М','Н','О','П','Р','С','Т','У','Ф',
'Х','Ч','Ц','Ш','Щ','Э','Ю','Я','Ы','Ъ','Ь',
'Э', 'Ю', 'Я');
return str_replace($small, $large, $string);
}
$rs=mysql_query("SELECT DISTINCT firstletter FROM mr_gazette WHERE firstletter!=' ' AND parent=0 ORDER BY firstletter");
while($one=mysql_fetch_array($rs)) $lettersarr[]=$one["firstletter"];
?><form name=findform action='index.php' method=get style="margin:10px 20px 20px 0px; text-align:right; ">
<font style='font:bold 8pt Tahoma;'><?
for ($i=0; $i<count($lettersarr);$i++) {
?><a href="index.php?&letter=<?=$lettersarr[$i]?>" style='font:bold 8pt Tahoma; text-transform:uppercase;'><?=_strtolower($lettersarr[$i])?></a><img src="img/null.gif" width=5><?
}
?></font>
<input type=hidden name="act" value="search">
<input type=text name=searchval class=frmtextsub> <input type=submit value='найти' class=mybutton style="width:50px; height:18px;">
</form><?
return $lettersarr;
}
T_T
форматирование сохранено