pvspeed Posted April 17, 2017 Report Posted April 17, 2017 $sql = " SELECT t.ticketid, t.subject, t.description, t.creator, t.created, t.updated, t.status, t.priority, t.server, (SELECT username FROM ".$this->prefix('users')." WHERE id=t.creator) AS owner FROM ".$this->prefix('tickets')." t ORDER BY ticketid DESC "; Vreau sa selectez din mysql din tabelul tickets ticketele care au creator userele din users care au parent = $_SESSION['user_id']; Am incercat asa: $sql = " SELECT t.ticketid, t.subject, t.description, t.creator, t.created, t.updated, t.status, t.priority, t.server, (SELECT username FROM ".$this->prefix('users')." WHERE id=t.creator) AS owner, (SELECT id FROM ".$this->prefix('users')." WHERE parent=".$_SESSION['user_id'].") AS plm FROM ".$this->prefix('tickets')." t WHERE t.creator=".$plm." ORDER BY ticketid DESC "; Ma poate ajuta cineva? Quote
Rubaka Posted April 17, 2017 Report Posted April 17, 2017 (edited) SELECT t.ticketid, t.subject, t.description, t.creator, t.created, t.updated, t.status, t.priority, t.server, FROM tabel_tckets AS t, tabel_users AS u WHERE u.parent = $_SESSION['user_id']; AND t.creator = u.id Edited April 17, 2017 by Rubaka 1 Quote
pvspeed Posted April 17, 2017 Author Report Posted April 17, 2017 $sql = " SELECT t.ticketid, t.subject, t.description, t.creator, t.created, t.updated, t.status, t.priority, t.server, (SELECT username FROM ".$this->prefix('users')." WHERE id=t.creator) AS owner FROM ".$this->prefix('tickets')." AS t ".(!$this->isAllowed(ADMIN) ? ', '.$this->prefix('users').' AS u WHERE u.parent='.$_SESSION['user_id'].' AND t.creator = u.id ' : ' ')." ORDER BY ticketid DESC "; Am introdus asta si a functionat dar vreau sa se afiseze si ticketele facute de $_SESSION['user_id']; $sql = " SELECT t.ticketid, t.subject, t.description, t.creator, t.created, t.updated, t.status, t.priority, t.server, (SELECT username FROM ".$this->prefix('users')." WHERE id=t.creator) AS owner FROM ".$this->prefix('tickets')." AS t ".(!$this->isAllowed(ADMIN) ? ', '.$this->prefix('users').' AS u WHERE t.creator='.$_SESSION['user_id'].' OR u.parent='.$_SESSION['user_id'].' AND t.creator = u.id ' : ' ')." ORDER BY ticketid DESC "; Am incercat asta dar ticketele facute de $_SESSION['user_id']; sunt afisate de 4 ori Quote
Wav3 Posted April 17, 2017 Report Posted April 17, 2017 Cauta despre left join ti-am zis. Nu mai fa cu subquery. Daca nu ii dai de cap iti fac eu query-ul. Quote
Wav3 Posted April 18, 2017 Report Posted April 18, 2017 (edited) Uite, ar veni cam asa. $sql = "SELECT tickets.ticketid, tickets.subject, tickets.description, tickets.creator, tickets.created, tickets.updated, tickets.status, tickets.priority, tickets.server, users.username FROM " . $this->prefix('tickets') . " AS tickets LEFT JOIN " . $this->prefix('users') . " AS users ON (tickets.creator = users.id) WHERE tickets.creator = '" . $_SESSION['user_id'] . "' OR users.parent = '" . $_SESSION['user_id'] . "' ORDER BY ticketid DESC"; Nu am inteles insa ce e cu IF-ul pentru isAllowed(ADMIN). Banuiesc ce face, dar pana acum nu ai zis nimic de el. Daca nu e bine cum ti-am dat, explica clar ce ai nevoie si iti fac 2 query-uri distincte. Recomand sa faci 2, pe if/else, decat 1 cu if-uri in linie. La un moment dat o sa te incurci in el daca esti si incepator. Edited April 18, 2017 by Wav3 3 Quote
UnixDevel Posted April 18, 2017 Report Posted April 18, 2017 nice din ce e asta , ca vad ca ar avea sql injection pe session_id 2 Quote