Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>PHP & SQL Server (sqlsrv)</title>
- </head>
- </head>
- <body>
- <div class="table-title">
- <h3>Test table</h3>
- <?php
- ini_set('display_errors', 1);
- error_reporting(~0);
- $serverName = "localhost";
- $userName = "username";
- $userPassword = "password";
- $dbName = "AdWorks";
- $connectionInfo = array("Database"=>$dbName, "UID"=>$userName, "PWD"=>$userPassword, "MultipleActiveResultSets"=>true);
- $conn = sqlsrv_connect( $serverName, $connectionInfo);
- if( $conn === false ) {
- die( print_r( sqlsrv_errors(), true));
- }
- ?>
- <form action="list.php" method="POST">
- <select name="RegSelect"><option> Choose </option>
- <?php
- $sql = "SELECT DISTINCT CountryRegionName FROM dbTest ORDER BY CountryRegionName";
- $resultRg = sqlsrv_query($conn,$sql) or die("Couldn't execut query");
- while ($data=sqlsrv_fetch_array($resultRg, SQLSRV_FETCH_ASSOC)){
- echo '<option value="'.$data['CountryRegionName'].'">';
- echo $data['CountryRegionName'];
- echo "</option>";
- }
- if(empty($_POST['RegSelect'])){
- $_SESSION['tower'] = '';
- } else {
- $stmt = "SELECT BusinessEntityID, FirstName, LastName, JobTitle, PhoneNumber, PhoneNumberType, EmailAddress, AddressLine1, City, PostalCode, CountryRegionName, Status FROM dbTest WHERE CountryRegionName = '".$_POST['RegSelect']."'";
- $qry = sqlsrv_query($conn, $stmt);
- }
- ?>
- <input type="submit" value="Select Tower">
- </select></br></br>
- </form>
- <table align="center">
- <tr>
- <th width="91"> <div align="center">BusinessEntityID </div></th>
- <th width="98"> <div align="center">FirstName </div></th>
- <th width="198"> <div align="center">LastName </div></th>
- <th width="97"> <div align="center">JobTitle </div></th>
- <th width="59"> <div align="center">PhoneNumber </div></th>
- <th width="71"> <div align="center">PhoneNumberType </div></th>
- <th width="30"> <div align="center">EmailAddress </div></th>
- <th width="30"> <div align="center">AddressLine1 </div></th>
- <th width="30"> <div align="center">City </div></th>
- <th width="30"> <div align="center">PostalCode </div></th>
- <th width="30"> <div align="center">CountryRegionName </div></th>
- <th width="30"> <div align="center">Status </div></a></th>
- <th width="30"> <div align="center">Edit </div></th>
- </tr>
- <tbody class="rows">
- <?php
- while($result = sqlsrv_fetch_array($qry, SQLSRV_FETCH_ASSOC)){
- //print_r($result);
- ?>
- <tr>
- <td><div align="center"><?=$result["BusinessEntityID"];?></div></td>
- <td><div align="center"><?=$result["FirstName"];?></div></td>
- <td><?=$result["LastName"];?></td>
- <td align="right"><?=$result["JobTitle"];?></td>
- <td align="right"><?=$result["PhoneNumber"];?></td>
- <td align="right"><?=$result["PhoneNumberType"];?></td>
- <td align="right"><?=$result["EmailAddress"];?></td>
- <td align="right"><?=$result["AddressLine1"];?></td>
- <td align="right"><?=$result["City"];?></td>
- <td align="right"><?=$result["PostalCode"];?></td>
- <td align="right"><?=$result["CountryRegionName"];?></td>
- <td align="right"><?=$result["Status"];?></td>
- <td align="center"><a href="edit_bck.php?BusinessEntityID=<?php echo $result["BusinessEntityID"];?>">Edit </a></td>
- </tr>
- <?php
- }
- ?>
- </table>
- <?php
- sqlsrv_close($conn);
- ?>
- </body>
- </html>
- <th onclick="sortBy('JobTitle', 'ASC')" width="91"> <div align="center">BusinessEntityID</div></th>
- <th onclick="sortBy('Status', 'DESC')" width="98"> <div align="center">FirstName</div></th>
- <script>
- function sortBy(columnName, order) {
- window.location.href = window.location.href.split('?')[0] + "?column=" + columnName + "&order=" + order;
- }
- //get the column name & sort type
- $columnName = isset($_REQUEST['column']) ? $_REQUEST['column'] : '';
- $order = isset($_REQUEST['order']) ? $_REQUEST['order'] : '';
- if (empty($_REQUEST['RegSelect'])) {
- $_SESSION['tower'] = '';
- } else {
- $stmt = "SELECT BusinessEntityID, FirstName, LastName, JobTitle, PhoneNumber, PhoneNumberType, EmailAddress, AddressLine1, City, PostalCode, CountryRegionName, Status FROM dbTest WHERE CountryRegionName = '" . $_REQUEST['RegSelect'] . "'";
- //append order by clause with type
- if (!empty($columnName)) {
- $stmt .= " ORDER BY $columnName $order";
- }
- $qry = sqlsrv_query($conn, $stmt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement