Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set('Asia/Hong_Kong');
- ini_set('error_log', 'logfile.txt');
- //Sets database connection information
- if (!(strpos($_SERVER["SERVER_NAME"], "localhost") === false)) {
- $hostname="localhost" ;
- $username="root" ;
- $password="root" ;
- $database="club" ;
- }
- try {
- $dbh = new PDO("mysql:host=$hostname;
- dbname=$database;
- charset=utf8", $username, $password
- );
- $dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- print "Error!: " . $e->getMessage() . "<br/>";
- die();
- }
- $sql = "SELECT DISTINCT sport FROM `club`
- ORDER BY sport";
- $rs = $dbh->prepare($sql);
- $rs->execute();
- $sportList = $rs->fetchAll(PDO::FETCH_ASSOC);
- print_r($sportList);
- $data = array(
- "sport" => "rugby",
- "familyName" => "Parker-Rauw"
- );
- $sql = "SELECT * FROM club WHERE sport = :sport AND familyname = :familyName";
- $rs = $dbh->prepare($sql);
- $rs->execute($data);
- while ($row = $rs->fetch()) {
- print_r($row);
- print "<br>";
- }
- ?>
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <?php
- echo "<form name='filter' method='post' action=''>";
- echo "<select name='sport'>";
- for($i=0; $i<count($sportList); $i++) {
- echo "<option value='".$sportList[$i]["sport"]."'>".$sportList[$i]["sport"]."</option>";
- }
- echo "</select>";
- echo "<input type='submit' name='submitFilter' value='Go' />";
- echo "</form>";
- // put your code here
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement