search in php pdo
respected sir,
can you plz provide the search in php pdo
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "add_query_pdo"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { } $sql = "SELECT tbl_registration_id, first_name, middle_name, last_name FROM tbl_registration"; $result1 = $conn->query($sql); if ($result1->num_rows > 0) { // output data of each row while($row1 = $result1->fetch_assoc()) { echo "id: " . $row1["tbl_registration_id"]. " - Name: " . $row1["first_name"]. " " . $row1["middle_name"]. " " . $row1["last_name"]. "<br>"; } } else { echo "0 results"; } $conn->close(); ?>
<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "add_query_pdo"; // Create connection // Check connection if (!$conn) { } $sql = "SELECT tbl_registration_id, first_name, middle_name, last_name FROM tbl_registration"; // output data of each row echo "id: " . $row["tbl_registration_id"]. " - Name: " . $row["first_name"]. " " . $row["middle_name"]. " " . $row["last_name"]. "<br>"; } } else { echo "0 results"; } ?>
<?php echo "<table style='border: solid 1px black;'>"; echo "<tr><th>Id</th><th>First Name</th><th>Middle Name</th><th>Last Name</th></tr>"; class TableRows extends RecursiveIteratorIterator { function __construct($it) { parent::__construct($it, self::LEAVES_ONLY); } } function beginChildren() { echo "<tr>"; } function endChildren() { echo "</tr>" . "\n"; } } $servername = "localhost"; $username = "root"; $password = ""; $dbname = "add_query_pdo"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT tbl_registration_id, first_name, middle_name, last_name FROM tbl_registration"); $stmt->execute(); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { echo $v; } } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; echo "</table>"; ?>
<table border="1" cellspacing="5" cellpadding="5" width="100%"> <thead> <tr> <th>No.</th> <th>First Name</th> <th>Middle Name</th> <th>Last Name</th> <th>Email</th> <th>Contact Number</th> </tr> </thead> <tbody> <?php require_once('connection.php'); $result = $conn->prepare("SELECT * FROM tbl_registration ORDER BY tbl_registration_id ASC"); $result->execute(); for($i=0; $row = $result->fetch(); $i++){ ?> <tr> <td><label><?php echo $row['tbl_registration_id']; ?></label></td> <td><label><?php echo $row['first_name']; ?></label></td> <td><label><?php echo $row['middle_name']; ?></label></td> <td><label><?php echo $row['last_name']; ?></label></td> <td><label><?php echo $row['email']; ?></label></td> <td><label><?php echo $row['contact_number']; ?></label></td> </tr> <?php } ?> </tbody> </table>