Sorting means arranging element in some specific order.
If the array element are integer or float type values then they are sorted to either in ascending order or descending order.
But if the array element are of char type then they are sorted in alphabetical order or reverse order.
The possible types of sorting to solve an array of integer type are as follow-:
1- Selection Sorting CLICK HERE
ads
Watch The Video Below
VIDEO
<?php
// Start the session (if not already started)
session_start();
// Check if the user is logged in, if not redirect to the login page
if (!isset($_SESSION['username'])) {
header("Location: login.html");
exit();
}
// Replace the following with your actual database credentials
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Establish a database connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check for a connection error
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if the search form is submitted
if (isset($_POST['search_query'])) {
// Sanitize the input to prevent SQL injection
$search_query = mysqli_real_escape_string($conn, $_POST['search_query']);
// Get the username of the currently logged-in user
$username = $_SESSION['username'];
// Prepare the SQL query to retrieve matching data for the current user
$sql = "SELECT * FROM user_details WHERE username = '$username' AND column_name LIKE '%$search_query%'";
// Execute the query and store the result
$result = $conn->query($sql);
// Check if there are any results
if ($result->num_rows > 0) {
// Display the search results in a table
echo "<table>";
while ($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row["column_name1"] . "</td>";
echo "<td>" . $row["column_name2"] . "</td>";
// Add more fields as needed
echo "</tr>";
}
echo "</table>";
} else {
echo "No results found.";
}
// Close the database connection
$conn->close();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>User Details Search</title>
</head>
<body>
<h2>Welcome, <?php echo $_SESSION['username']; ?></h2>
<form action="search.php" method="POST">
<label for="search">Search:</label>
<input type="text" id="search" name="search_query" placeholder="Enter search term..." required>
<button type="submit">Search</button>
</form>
</body>
</html>
please share
ReplyDelete