To create a PHP script that connects to a MySQL database, retrieves all records from a table named "employees" with columns "id", "first_name", "last_name", "email", and "salary", and displays the results in an HTML table, follow these steps:

1. Create a new PHP file (e.g., `index.php`).
2. Add the following code to connect to your MySQL database:

```php
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>
```

Replace `"your_username"`, `"your_password"`, and `"your_database"` with your actual MySQL credentials.

3. Add the following code to retrieve all records from the "employees" table and sort them based on the selected column:

```php
<?php
$order_by = isset($_GET['order_by']) ? $_GET['order_by'] : 'id';
$order_dir = isset($_GET['order_dir']) ? $_GET['order_dir'] : 'ASC';

$sql = "SELECT id, first_name, last_name, email, salary FROM employees ORDER BY {$order_by} {$order_dir}";
$result = $conn->query($sql);
?>
```

4. Add the following code to display the retrieved records in an HTML table:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Employees</title>
</head>
<body>
    <table border="1">
        <thead>
            <tr>
                <th><a href="?order_by=id&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">ID</a></th>
                <th><a href="?order_by=first_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">First Name</a></th>
                <th><a href="?order_by=last_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Last Name</a></th>
                <th><a href="?order_by=email&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Email</a></th>
                <th><a href="?order_by=salary&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Salary</a></th>
            </tr>
        </thead>
        <tbody>
            <?php
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<td>" . $row["id"] . "</td>";
                    echo "<td>" . $row["first_name"] . "</td>";
                    echo "<td>" . $row["last_name"] . "</td>";
                    echo "<td>" . $row["email"] . "</td>";
                    echo "<td>" . $row["salary"] . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan='5'>No records found</td></tr>";
            }
            ?>
        </tbody>
    </table>
</body>
</html>
```

5. Finally, close the MySQL connection:

```php
<?php
$conn->close();
?>
```

The complete `index.php` file should look like this:

```php
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$order_by = isset($_GET['order_by']) ? $_GET['order_by'] : 'id';
$order_dir = isset($_GET['order_dir']) ? $_GET['order_dir'] : 'ASC';

$sql = "SELECT id, first_name, last_name, email, salary FROM employees ORDER BY {$order_by} {$order_dir}";
$result = $conn->query($sql);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Employees</title>
</head>
<body>
    <table border="1">
        <thead>
            <tr>
                <th><a href="?order_by=id&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">ID</a></th>
                <th><a href="?order_by=first_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">First Name</a></th>
                <th><a href="?order_by=last_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Last Name</a></th>
                <th><a href="?order_by=email&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Email</a></th>
                <th><a href="?order_by=salary&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Salary</a></th>
            </tr>
        </thead>
        <tbody>
            <?php
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<td>" . $row["id"] . "</td>";
                    echo "<td>" . $row["first_name"] . "</td>";
                    echo "<td>" . $row["last_name"] . "</td>";
                    echo "<td>" . $row["email"] . "</td>";
                    echo "<td>" . $row["salary"] . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan='5'>No records found</td></tr>";
            }
            ?>
        </tbody>
    </table>
</body>
</html>

<?php
$conn->close();
?>
```

Now, when you open `index.php` in your browser, it should display the "employees" table data and allow you to sort by any column by clicking on its header.
MySQL 데이터베이스에 연결하여 "id", "first_name", "last_name", "email", "salary" 열이 있는 "employees"라는 테이블에서 모든 레코드를 검색하고 결과를 HTML 테이블에 표시하는 PHP 스크립트를 만들려면 다음 단계를 따르세요.

1. 새 PHP 파일(예: `index.php`)을 만듭니다.
2. 다음 코드를 추가하여 MySQL 데이터베이스에 연결합니다:

```php
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>
```

`"your_username"`, `"your_password"` 및 `"your_database"`를 실제 MySQL 자격 증명으로 바꿉니다.

3. 다음 코드를 추가하여 "employees" 테이블에서 모든 레코드를 검색하고 선택한 열을 기준으로 정렬합니다:

```php
<?php
$order_by = isset($_GET['order_by']) ? $_GET['order_by'] : 'id';
$order_dir = isset($_GET['order_dir']) ? $_GET['order_dir'] : 'ASC';

$sql = "SELECT id, first_name, last_name, email, salary FROM employees ORDER BY {$order_by} {$order_dir}";
$result = $conn->query($sql);
?>
```

4. 검색된 레코드를 HTML 테이블에 표시하려면 다음 코드를 추가합니다:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Employees</title>
</head>
<body>
    <table border="1">
        <thead>
            <tr>
                <th><a href="?order_by=id&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">ID</a></th>
                <th><a href="?order_by=first_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">First Name</a></th>
                <th><a href="?order_by=last_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Last Name</a></th>
                <th><a href="?order_by=email&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Email</a></th>
                <th><a href="?order_by=salary&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Salary</a></th>
            </tr>
        </thead>
        <tbody>
            <?php
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<td>" . $row["id"] . "</td>";
                    echo "<td>" . $row["first_name"] . "</td>";
                    echo "<td>" . $row["last_name"] . "</td>";
                    echo "<td>" . $row["email"] . "</td>";
                    echo "<td>" . $row["salary"] . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan='5'>No records found</td></tr>";
            }
            ?>
        </tbody>
    </table>
</body>
</html>
```

5. 마지막으로 MySQL 연결을 닫습니다:

```php
<?php
$conn->close();
?>
```

전체 `index.php` 파일은 다음과 같아야 합니다:

```php
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$order_by = isset($_GET['order_by']) ? $_GET['order_by'] : 'id';
$order_dir = isset($_GET['order_dir']) ? $_GET['order_dir'] : 'ASC';

$sql = "SELECT id, first_name, last_name, email, salary FROM employees ORDER BY {$order_by} {$order_dir}";
$result = $conn->query($sql);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Employees</title>
</head>
<body>
    <table border="1">
        <thead>
            <tr>
                <th><a href="?order_by=id&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">ID</a></th>
                <th><a href="?order_by=first_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">First Name</a></th>
                <th><a href="?order_by=last_name&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Last Name</a></th>
                <th><a href="?order_by=email&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Email</a></th>
                <th><a href="?order_by=salary&order_dir=<?= $order_dir === 'ASC' ? 'DESC' : 'ASC' ?>">Salary</a></th>
            </tr>
        </thead>
        <tbody>
            <?php
            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<tr>";
                    echo "<td>" . $row["id"] . "</td>";
                    echo "<td>" . $row["first_name"] . "</td>";
                    echo "<td>" . $row["last_name"] . "</td>";
                    echo "<td>" . $row["email"] . "</td>";
                    echo "<td>" . $row["salary"] . "</td>";
                    echo "</tr>";
                }
            } else {
                echo "<tr><td colspan='5'>No records found</td></tr>";
            }
            ?>
        </tbody>
    </table>
</body>
</html>

<?php
$conn->close();
?>
```

이제 브라우저에서 `index.php`를 열면 "employees" 테이블 데이터가 표시되고 헤더를 클릭하여 원하는 열을 기준으로 정렬할 수 있습니다.