Guest User

Untitled

a guest
Jun 28th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 4.11 KB | None | 0 0
  1. <?php session_start(); ?>
  2. <html>
  3.     <head>
  4.         <title>PHP/PostgreSQL-test</title>
  5.     </head>
  6.     <body>
  7.         <?php
  8.             //phpinfo();
  9.             $link = pg_connect("host=psql-vt2012 dbname=liner user=liner password=lDrHtHAP");
  10.             $result = pg_exec($link, "select * from bostader");
  11.             $numrows = pg_numrows($result);
  12.         ?>
  13.        
  14.         <?php
  15.             echo "<h3>  Län           Objekttyp     Antal rum </h3>";
  16.            
  17.             // Ett form för att välja.
  18.             echo "<form action = \"result.php\" method=\"post\">";
  19.                 foreach(array("lan", "objekttyp", "rum") as $s){
  20.                     $tmp = array();
  21.                     for($ri = 0; $ri < $numrows; $ri++) {
  22.                         $row = pg_fetch_array($result, $ri);
  23.                         if(!in_array($row[$s], $tmp)){
  24.                             array_push($tmp, $row[$s]);
  25.                         }
  26.                     }
  27.                     echo "<select name=\"" . $s . "\">";
  28.                         for($i = 0; $i < count($tmp); $i++){
  29.                             if($_SESSION[$s] == $tmp[$i])
  30.                                 echo "<option value=" . $tmp[$i] . " selected=\"selected\">" . $tmp[$i] . "</option>";
  31.                             else
  32.                                 echo "<option value=" . $tmp[$i] . ">" . $tmp[$i] . "</option>";
  33.                            
  34.                         }
  35.                     echo "</select>";
  36.                 }
  37.                
  38.                 echo "<input type=\"submit\" value=\"Sök\" />";
  39.             echo "</form>";
  40.            
  41.            
  42.         ?>
  43.        
  44.         <?php
  45.             pg_close($link);
  46.         ?>
  47.     </body>
  48. </html>
  49.  
  50.  
  51. ===================RESULT ========================
  52.  
  53. <?php session_start(); ?>
  54.  
  55. <html>
  56. <head>
  57.     <script src="sorttable.js"></script>
  58. </head>
  59. <body>
  60.     <?php
  61.     $_SESSION['lan'] = $_POST['lan'];
  62.     $_SESSION['objekttyp'] = $_POST['objekttyp'];
  63.     $_SESSION['rum'] = $_POST['rum'];
  64.     $lanet = $_POST["lan"];
  65.     $typen = $_POST["objekttyp"];
  66.     $rummet = $_POST["rum"];
  67.     $ordning = "pris";
  68.     if(!empty($_POST["ordning"])){
  69.         $ordning = $_POST["ordning"];
  70.     }
  71.  
  72.     //phpinfo();
  73.     $link = pg_connect("host=psql-vt2012 dbname=liner user=liner password=lDrHtHAP");
  74.     $result = pg_exec($link, "select * from bostader WHERE lan='" . $lanet .
  75.                  "' AND objekttyp='" . $typen . "' AND rum>='" . $rummet .
  76.                  "' ORDER BY " . $ordning . " ASC;");
  77.     $numrows = pg_numrows($result);
  78.     $prisf = "<form action=\"result.php\" method =\"post\">
  79.             <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
  80.             <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
  81.             <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
  82.             <input type=\"hidden\" name=\"ordning\" value=\"pris\" />
  83.             <input type=\"submit\" value=\"Pris\" />
  84.             </form>";
  85.            
  86.     $areaf = "<form action=\"result.php\" method =\"post\">
  87.             <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
  88.             <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
  89.             <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
  90.             <input type=\"hidden\" name=\"ordning\" value=\"area\" />
  91.             <input type=\"submit\" value=\"Area\" />
  92.             </form>";
  93.            
  94.     $rumf = "<form action=\"result.php\" method =\"post\">
  95.             <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
  96.             <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
  97.             <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
  98.             <input type=\"hidden\" name=\"ordning\" value=\"rum\" />
  99.             <input type=\"submit\" value=\"Rum\" />
  100.             </form>";
  101.            
  102.     function sortera($s){
  103.         return "<form action=\"result.php\" method =\"post\">
  104.             <input type=\"hidden\" name=\"lan\" value=\"" . $lanet . "\"/>
  105.             <input type=\"hidden\" name=\"objekttyp\" value=\"" . $typen . "\"/>
  106.             <input type=\"hidden\" name=\"rum\" value=\"" . $rummet . "\"/>
  107.             <input type=\"hidden\" name=\"ordning\" value=\"" . $s . "\" />
  108.             <input type=\"submit\" value=\"" . $s . "\" />
  109.             </form>";
  110.     }
  111.     ?>
  112.  
  113.     <?php
  114.     $area = sortera("area");
  115.     $rum = sortera("rum");
  116.     $pris = sortera("pris");
  117.  
  118.     echo "<table border=\"1\"> <tr> <th>Län</th> <th>Objekttyp</th> <th>Adress</th> <th>".$areaf."</th>
  119.                     <th>".$rumf."</th> <th>".$prisf."</th> <th>Avgift</th> </tr>";
  120.        
  121.             for($ri = 0; $ri < $numrows; $ri++) {
  122.                 echo "<tr>\n";
  123.                 $row = pg_fetch_array($result, $ri);
  124.                 $i = 0;
  125.                 while($row[$i] != null){
  126.                     echo " <td>", $row[$i], "</td>";
  127.                     $i++;
  128.                 }
  129.                 echo "</tr>";
  130.             }
  131.             pg_close($link);
  132.         ?>
  133.     </table>
  134.  
  135.     ?>
  136. </body>
  137. </html>
Add Comment
Please, Sign In to add comment