<!-- PHP code to establish connection with the localserver -->
<?php

// Username is root
$user = 'playtimeparadise_sumit';
$password = 'playtimeparadise_sumit';

// Database name is geeksforgeeks
$database = 'playtimeparadise_sumit';

// Server is localhost with
// port number 3306
$servername='localhost';
$mysqli = new mysqli($servername, $user,
				$password, $database);

// Checking for connections
if ($mysqli->connect_error) {
	die('Connect Error (' .
	$mysqli->connect_errno . ') '.
	$mysqli->connect_error);
}

// SQL query to select data from database
$sql = " SELECT * FROM newemail";
$result = $mysqli->query($sql);
$mysqli->close();
?>
<!-- HTML code to display data in tabular format -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<title>Sky Team Leads</title>
	<!-- CSS FOR STYLING THE PAGE -->
	<style>
		table {
			margin: 0 auto;
			font-size: large;
			border: 1px solid black;
		}

		h1 {
			text-align: center;
			color: #006600;
			font-size: xx-large;
			font-family: 'Gill Sans', 'Gill Sans MT',
			' Calibri', 'Trebuchet MS', 'sans-serif';
		}

		td {
			background-color: #E4F5D4;
			border: 1px solid black;
		}

		th,
		td {
			font-weight: bold;
			border: 1px solid black;
			padding: 10px;
			text-align: center;
		}

		td {
			font-weight: lighter;
		}
	
		tr.copy-row {
            cursor: pointer;
        }
	</style>
</head>

<body>
	<section>
		<h1>Sky Team Leads</h1>
		<!-- TABLE CONSTRUCTION -->
		<table id="myTable">
			<tr>
			    			
<th>Sl.No</th>
				<th>Trip Type</th>
				<th>From</th>
				<th>To</th>
					<th>Date 1</th>
						<th>Date 2</th>
							<th>Passenger</th>
								<th>Class</th>	<th>Name</th><th>Email</th><th>Phone</th>
								
			</tr>
			<!-- PHP CODE TO FETCH DATA FROM ROWS -->
			<?php
				// LOOP TILL END OF DATA
				while($rows=$result->fetch_assoc())
				{
			?>
			<tr class="copy-row">
				<!-- FETCHING DATA FROM EACH
					ROW OF EVERY COLUMN -->
								
<td></td>
				<td><?php echo $rows['tripType'];?> |</td>
				<td><?php echo $rows['from_ap1'];?> |</td>
				<td><?php echo $rows['to_ap1'];?> |</td>
				<td><?php echo $rows['date_ap1'];?> |</td>
				<td><?php echo $rows['date_ap2'];?> |</td>
				<td><?php echo $rows['psngr'];?> |</td>
				<td><?php echo $rows['clas'];?> |</td>
				<td><?php echo $rows['name'];?> |</td>
				<td><?php echo $rows['email'];?> |</td>
				<td><?php echo $rows['phone'];?></td>
				
			</tr>
			<?php
				}
			?>
		</table>
	</section>
	 	<script>
	
        // Add event listener to table rows with class "copy-row"
        var copyRows = document.getElementsByClassName("copy-row");
        for (var i = 0; i < copyRows.length; i++) {
            copyRows[i].addEventListener("click", function() {
                var rowText = "";
                var rowCells = this.getElementsByTagName("td");
                for (var j = 0; j < rowCells.length; j++) {
                    rowText += rowCells[j].innerText + " ";
                }
                var tempInput = document.createElement("input");
                document.body.appendChild(tempInput);
                tempInput.value = rowText;
                tempInput.select();
                tempInput.setSelectionRange(0, 99999);
                document.execCommand("copy");
                document.body.removeChild(tempInput);
                alert("Text has been copied: " + rowText);
            });
        }
        // Get the table element by its ID
        var table = document.getElementById("myTable");

        // Get all the rows in the table, excluding the header row
        var rows = table.getElementsByTagName("tr");
        for (var i = 1; i < rows.length; i++) {
            // Set the text content of the first cell in each row to the serial number
            rows[i].getElementsByTagName("td")[0].textContent = i;
        }
    </script>
</body>

</html>
