public function filterItems() { $dbObj = new DB_Class(); $db = $dbObj->connect(); $query = 'SELECT * FROM items WHERE '; if (!empty($_POST['priceA']) || $_POST['priceA'] == '0') { if (empty($_POST['priceB'])) { $query .= 'price > ' . $_POST["priceA"] . ' AND '; } else { $query .= 'price BETWEEN ' . $_POST["priceA"] . ' AND ' . $_POST["priceB"] . ' AND '; } } else { if (empty($_POST['priceB'])) { $query .= 'price > 0 AND '; } else { $query .= 'price < ' . $_POST["priceB"] . ' AND '; } } if (!empty($_POST['yearA']) || $_POST['yearA'] == '0') { if (empty($_POST['yearB'])) { $query .= 'year > ' . $_POST["yearA"] . ' AND '; } else { $query .= 'year BETWEEN ' . $_POST["yearA"] . ' AND ' . $_POST["yearB"] . ' AND '; } } else { if (empty($_POST['yearB'])) { $query .= 'year > 0 AND '; } else { $query .= 'year < ' . $_POST["yearB"] . ' AND '; } } if (!empty($_POST['horseA']) || $_POST['horseA'] == '0') { if (empty($_POST['horseB'])) { $query .= 'horsepower > ' . $_POST["horseA"] . ' '; } else { $query .= 'horsepower BETWEEN ' . $_POST["horseA"] . ' AND ' . $_POST["horseB"] . ' '; } } else { if (empty($_POST['horseB'])) { $query .= 'horsepower > 0 '; } else { $query .= 'horsepower < ' . $_POST["horseB"] . ' '; } } $result = $db->query($query); return $result; }
public function showBasket() { $dbObj = new DB_Class(); $db = $dbObj->connect(); $uid = $_SESSION['uid']; $result = $db->query('SELECT item_ids FROM basket WHERE user_id=' . $uid . ' '); $result = $result->fetch(PDO::FETCH_ASSOC); $items = explode(' ', $result['item_ids']); $result2 = $db->query('SELECT * FROM items'); $result3 = array(); $i = 0; foreach ($result2 as $key) { if (strstr($result['item_ids'], $key['id'])) { $result3[$i++] = $key; } } return $result3; }
<header class="jumbotron subhead" id="overview"> <h1>Query b, Deliverable 3</h1> <p class="lead">List the name of the schools according to the number of players they sent to the ABA. Sort them in descending order by number of drafted players.</p> <pre> SELECT draftedFrom, COUNT(*) as nbr FROM Draft WHERE league = 'A' GROUP BY draftedFrom ORDER BY nbr DESC </pre> </header> <?php $connection = new DB_Class(); ?> <?php $connection->connect(); ?> <?php $query = "\nSELECT draftedFrom, COUNT(*) as nbr \nFROM Draft \nWHERE league = 'A' \nGROUP BY draftedFrom \nORDER BY nbr DESC"; ?> <p><?php echo $connection->count_results($query); ?> results found.</p> <?php $data = $connection->fetch($query); ?> <table class="table table-striped"> <thead> <tr> <th>Firstname</th>