Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = '127.0.0.1';
- $user = 'root';
- $pass = '';
- $name = 'pw';
- $con = new mysqli($host, $user, $pass, $name) or die("Can't connect");
- $criterii = json_decode($_REQUEST["criterii"]);
- $elements = "";
- if ($criterii->empty == 'true') {
- $query = 'SELECT * FROM laptops';
- $result = $con->query($query);
- while ($rows = $result->fetch_assoc()) {
- $elements .= $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- }
- } else {
- $prods = array();
- $processors = array();
- $memories = array();
- $hdds = array();
- $videoCards = array();
- $allEl = array();
- $query = 'SELECT * FROM laptops';
- $result = $con->query($query);
- while ($rows = $result->fetch_assoc()) {
- $el = $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- array_push($allEl, $el);
- }
- foreach ($criterii->Producator as $prod) {
- $query = 'SELECT * FROM laptops WHERE Producator=?';
- $stmt = $con->prepare($query);
- if ($stmt === false) {
- trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $connection->errno . ' ' . $connection->error, E_USER_ERROR);
- }
- $stmt->bind_param('s', $prod);
- $stmt->execute();
- $result = $stmt->get_result();
- while ($rows = $result->fetch_array(MYSQLI_ASSOC)) {
- $el = $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- array_push($prods, $el);
- }
- }
- foreach ($criterii->Procesor as $prod) {
- $query = 'SELECT * FROM laptops WHERE Procesor=?';
- $stmt = $con->prepare($query);
- if ($stmt === false) {
- trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $connection->errno . ' ' . $connection->error, E_USER_ERROR);
- }
- $stmt->bind_param('s', $prod);
- $stmt->execute();
- $result = $stmt->get_result();
- while ($rows = $result->fetch_array(MYSQLI_ASSOC)) {
- $el = $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- array_push($processors, $el);
- }
- }
- foreach ($criterii->Memorie as $prod) {
- $query = 'SELECT * FROM laptops WHERE Memorie=?';
- $stmt = $con->prepare($query);
- if ($stmt === false) {
- trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $connection->errno . ' ' . $connection->error, E_USER_ERROR);
- }
- $stmt->bind_param('s', $prod);
- $stmt->execute();
- $result = $stmt->get_result();
- while ($rows = $result->fetch_array(MYSQLI_ASSOC)) {
- $el = $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- array_push($memories, $el);
- }
- }
- foreach ($criterii->HDD as $prod) {
- $query = 'SELECT * FROM laptops WHERE HDD=?';
- $stmt = $con->prepare($query);
- if ($stmt === false) {
- trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $connection->errno . ' ' . $connection->error, E_USER_ERROR);
- }
- $stmt->bind_param('s', $prod);
- $stmt->execute();
- $result = $stmt->get_result();
- while ($rows = $result->fetch_array(MYSQLI_ASSOC)) {
- $el = $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- array_push($hdds, $el);
- }
- }
- foreach ($criterii->PlacaVideo as $prod) {
- $query = 'SELECT * FROM laptops WHERE PlacaVideo=?';
- $stmt = $con->prepare($query);
- if ($stmt === false) {
- trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $connection->errno . ' ' . $connection->error, E_USER_ERROR);
- }
- $stmt->bind_param('s', $prod);
- $stmt->execute();
- $result = $stmt->get_result();
- while ($rows = $result->fetch_array(MYSQLI_ASSOC)) {
- $el = $rows['Producator'] . ' ' . $rows['Procesor'] . ' ' . $rows['Memorie'] . ' ' . $rows['HDD'] . ' ' . $rows['PlacaVideo'] . '<br>';
- array_push($videoCards, $el);
- }
- }
- if (sizeof($prods) > 0) $allEl = array_intersect($allEl, $prods);
- if (sizeof($processors) > 0) $allEl = array_intersect($allEl, $processors);
- if (sizeof($memories) > 0) $allEl = array_intersect($allEl, $memories);
- if (sizeof($hdds) > 0) $allEl = array_intersect($allEl, $hdds);
- if (sizeof($videoCards) > 0) $allEl = array_intersect($allEl, $videoCards);
- foreach ($allEl as $el) {
- $elements .= $el;
- }
- $con->close();
- }
- echo $elements;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement