From cdbb724234ee7bb866f75b7f4dda7f76a2139f9c Mon Sep 17 00:00:00 2001 From: lopar Date: Sat, 22 Jun 2019 12:34:23 +0300 Subject: [PATCH] fucking sql query --- admin/admin.php | 2 +- zayavka.php | 63 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/admin/admin.php b/admin/admin.php index d7cbad1..5271ac2 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -8,7 +8,7 @@ session_start(); require_once '../functions.php'; - +db::c()->prepare(); if (empty($user['admin'])) { echo "404 Not Found

Not Found

The requested URL {$_SERVER['SCRIPT_NAME']} was not found on this server.


Apache/2.2.22 (@RELEASE@) Server at Hetzner Datacenter 426
"; exit; diff --git a/zayavka.php b/zayavka.php index 235a951..cb1960b 100644 --- a/zayavka.php +++ b/zayavka.php @@ -53,6 +53,13 @@ class zayavka function getlist($razdel = 1, $level = null, $id = null) { /* + * $level - заявки какого уровня мне показывать + * $razdel - тип поединка + * 1 - нубы + * 2 - физы + * 4 - группы + * 5 - хаос + * * if ($level AND $razdel==4 AND $id): * SELECT * FROM `zayavka` WHERE * (`t1min` <= {$level} OR `t1min` = 99) AND @@ -75,19 +82,65 @@ class zayavka * (`t1max` >= {$level} OR `t1max` = 99) AND * `level` = {$razdel} * + * if ($level AND $razdel==4 AND !$id): + * SELECT * FROM `zayavka` WHERE + * (`t1min` <= {$level} OR `t1min` = 99) AND + * (`t1max` >= {$level} OR `t1max` = 99) AND + * (`t2min` <= {$level} OR `t2min` = 99) AND + * (`t2max` >= {$level} OR `t2max` = 99) AND + * `level` = {$razdel} + * + * if (!$level AND $id): + * SELECT * FROM `zayavka` WHERE + * `level` = {$razdel} + * `id` = {$id} + * + * if (!$level AND !$id): + * SELECT * FROM `zayavka` WHERE + * `level` = {$razdel} + * * Пидорасы! */ - $fict = mysql_query("SELECT * FROM `zayavka` WHERE " . (($level != null) ? " ((`t1min` <= '{$level}' OR `t1min` = '99') AND (`t1max` >= '{$level}' OR `t1max` = '99') " . (($razdel == 4) ? "AND (`t2min` <= '{$level}' OR `t2min` = '99') AND (`t2max` >= '{$level}' OR `t2max` = '99')" : "") . ") AND " : "") . " `level` = {$razdel} " . (($id != null) ? " AND `id` = {$id} " : "") . " ORDER BY `podan` DESC"); - while ($row = mysql_fetch_array($fict)) { + + $sql = db::c()->prepare('SELECT * FROM `zayavka` WHERE `level` = ?i', $razdel); + if (!is_null($level)) { + $sql .= db::c()->prepare('AND (`t1min` <= ?i OR `t1min` = 99) AND (`t1max` >= ?i OR `t1max` = 99)', $level, $level); + if (4 == $razdel) { + $sql .= db::c()->prepare('AND (`t2min` <= ?i OR `t2min` = 99) AND (`t2max` >= ?i OR `t2max` = 99)', $level, $level); + } + } + if (!is_null($id)) { + $sql .= db::c()->prepare('AND `id` = ?i', $id); + } + + $fict = db::c()->query($sql); + +// $fict = mysql_query(" +//SELECT * FROM `zayavka` +//WHERE " . +// (($level != null) ? +// " ((`t1min` <= '{$level}' OR `t1min` = '99') AND (`t1max` >= '{$level}' OR `t1max` = '99') " +// . (($razdel == 4) ? +// "AND (`t2min` <= '{$level}' OR `t2min` = '99') AND (`t2max` >= '{$level}' OR `t2max` = '99')" +// : "") +// . ") AND " +// : "") +// . " `level` = {$razdel} " +// . (($id != null) ? +// " AND `id` = {$id} " +// : "") +// . " ORDER BY `podan` DESC"); + + while ($row = $fict->fetch_assoc()) { if (($row['start'] + 300) < time()) { - if (mysql_query("DELETE FROM `zayavka` WHERE `id` = '{$row['id']}' LIMIT 1")) { + if (db::c()->query('DELETE FROM `zayavka` WHERE `id` = ?i', $row['id'])) { $team1 = $this->fteam($row['team1']); foreach ($team1 as $k => $v) { - mysql_query("UPDATE `users` SET `zayavka` = '0' WHERE `id` = {$v}"); + db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v); } $team2 = $this->fteam($row['team2']); foreach ($z[$zay]['team2'] as $k => $v) { - mysql_query("UPDATE `users` SET `zayavka` = '0' WHERE `id` = {$v}"); + db::c()->query('UPDATE `users` SET `zayavka` = 0 WHERE `id` = ?i', $v); } } }