$servername = "localhost"; $username = "username"; $password = "password"; $dbname = "myDB"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // SQL query to select data from table $sql = "SELECT * FROM table_name WHERE condition"; // Execute query and store result $result = mysqli_query($conn, $sql); // Loop through result set and print data if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo "Id: " . $row["id"]. " - Name: " . $row["name"]. " - Age: " . $row["age"]. "This example demonstrates how to use the `mysqli_query()` function in PHP to select data from a table in a MySQL database. The `mysqli_fetch_assoc()` function is used to fetch each row of data as an associative array, which can then be printed to the webpage. The package library used in this example is the MySQL extension for PHP, which is included in most PHP installations by default. Overall, the table select function is an essential tool for retrieving data from databases using PHP, allowing for dynamic and customizable web applications.
"; } } else { echo "0 results"; } // Close connection mysqli_close($conn);