How can PHP developers ensure that each database result opens in a new window instead of overwriting the existing one?
When displaying database results in PHP, developers can ensure that each result opens in a new window by including the target="_blank" attribute in the anchor tag (<a>). This attribute tells the browser to open the link in a new tab or window instead of overwriting the current page.
<?php
// Sample database query
$results = $pdo->query("SELECT * FROM table");
// Displaying results in a loop
foreach ($results as $result) {
echo "<a href='details.php?id=" . $result['id'] . "' target='_blank'>" . $result['name'] . "</a><br>";
}
?>
Related Questions
- How can the use of translation tools like Google or Deepl enhance code readability and communication in multilingual PHP development projects?
- What is the purpose of using $_SESSION['server_SID'] in a PHP login system?
- What potential issues can arise when trying to read a CSV file from an external link using PHP?