Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start(); ?>
- <html>
- <head>
- <title>PHP/PostgreSQL-test</title>
- </head>
- <body>
- <?php
- //phpinfo();
- $link = pg_connect("host=psql-vt2012 dbname=liner user=liner password=lDrHtHAP");
- $result = pg_exec($link, "select * from bostader");
- $numrows = pg_numrows($result);
- ?>
- <?php
- echo "<h3> Län Objekttyp Antal rum </h3>";
- // Ett form för att välja.
- echo "<form action = \"result.php\" method=\"post\">";
- foreach(array("lan", "objekttyp", "rum") as $s){
- $tmp = array();
- for($ri = 0; $ri < $numrows; $ri++) {
- $row = pg_fetch_array($result, $ri);
- if(!in_array($row[$s], $tmp)){
- array_push($tmp, $row[$s]);
- }
- }
- echo "<select name=\"" . $s . "\">";
- for($i = 0; $i < count($tmp); $i++){
- if($_SESSION[$s] == $tmp[$i])
- echo "<option value=" . $tmp[$i] . " selected=\"selected\">" . $tmp[$i] . "</option>";
- else
- echo "<option value=" . $tmp[$i] . ">" . $tmp[$i] . "</option>";
- }
- echo "</select>";
- }
- echo "<input type=\"submit\" value=\"Sök\" />";
- echo "</form>";
- ?>
- <?php
- pg_close($link);
- ?>
- </body>
- </html>
- ===================RESULT ========================
- <?php session_start(); ?>
- <html>
- <head>
- <script src="sorttable.js"></script>
- </head>
- <body>
- <?php
- $_SESSION['lan'] = $_POST['lan'];
- $_SESSION['objekttyp'] = $_POST['objekttyp'];
- $_SESSION['rum'] = $_POST['rum'];
- $lanet = $_POST["lan"];
- $typen = $_POST["objekttyp"];
- $rummet = $_POST["rum"];
- $ordning = "pris";
- if(!empty($_POST["ordning"])){
- $ordning = $_POST["ordning"];
- }
- //phpinfo();
- $link = pg_connect("host=psql-vt2012 dbname=liner user=liner password=lDrHtHAP");
- $result = pg_exec($link, "select * from bostader WHERE lan='" . $lanet .
- "' AND objekttyp='" . $typen . "' AND rum>='" . $rummet .
- "' ORDER BY " . $ordning . " ASC;");
- $numrows = pg_numrows($result);
- $prisf = "<form action=\"result.php\" method =\"post\">
- <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
- <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
- <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
- <input type=\"hidden\" name=\"ordning\" value=\"pris\" />
- <input type=\"submit\" value=\"Pris\" />
- </form>";
- $areaf = "<form action=\"result.php\" method =\"post\">
- <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
- <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
- <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
- <input type=\"hidden\" name=\"ordning\" value=\"area\" />
- <input type=\"submit\" value=\"Area\" />
- </form>";
- $rumf = "<form action=\"result.php\" method =\"post\">
- <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
- <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
- <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
- <input type=\"hidden\" name=\"ordning\" value=\"rum\" />
- <input type=\"submit\" value=\"Rum\" />
- </form>";
- function sortera($s){
- return "<form action=\"result.php\" method =\"post\">
- <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
- <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
- <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
- <input type=\"hidden\" name=\"ordning\" value=\"" . $s . "\" />
- <input type=\"submit\" value=\"" . $s . "\" />
- </form>";
- }
- ?>
- <?php
- $area = sortera("area");
- $rum = sortera("rum");
- $pris = sortera("pris");
- echo "<table border=\"1\"> <tr> <th>Län</th> <th>Objekttyp</th> <th>Adress</th> <th>".$areaf."</th>
- <th>".$rumf."</th> <th>".$prisf."</th> <th>Avgift</th> </tr>";
- for($ri = 0; $ri < $numrows; $ri++) {
- echo "<tr>\n";
- $row = pg_fetch_array($result, $ri);
- $i = 0;
- while($row[$i] != null){
- echo " <td>", $row[$i], "</td>";
- $i++;
- }
- echo "</tr>";
- }
- pg_close($link);
- ?>
- </table>
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment