Part-4: Display Records using prepared statement
Part-4: Display Records using prepared statement.
In part four, we concentrate on fetching record from database using prepared statement. We use select SQL statement to retrieve all record from table. After executing our query using PDO object we check whether it return the rows or not. If it does not return records then “No record found.” Message will be shown otherwise record will be display in HTML table. Last two column have link for Edit and Update record. When user click on it, it pass id to edit or delete page using default GET method.
display.php
<?php
require "conn.php";
try
{
$stmt = $conn->prepare("SELECT id, name, email, phone FROM tbl");
$stmt->execute();
# setting the fetch mode
$result = $stmt->fetchAll();
if( ! $result)
{
print('No Records Found');
}
else
{
echo "<table border='1' align='center' cellpadding='5px' cellspacing='2px'>";
//while($row = $stmt->fetch())
echo "<tr><th>ID</th><th>Name</th><th>Email</th><th>Phone</th><th colspan='2'></th></tr>";
foreach($result as $row)
{
echo "<tr>";
echo "<td>";
echo $row['id'];
echo "</td>";
echo "<td>";
echo $row['name'];
echo "</td>";
echo "<td>";
echo $row['email'];
echo "</td>";
echo "<td>";
echo $row['phone'];
echo "</td>";
echo "<td>";
$search_str=$row['id'];
echo "<a href='edit.php?id=$search_str'>Edit</a>";
echo "</td>";
echo "<td>";
$search_str=$row['id'];
echo "<a href='delete.php?id=$search_str'>Delete</a>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
This example is divided in multiple part.
Part-1: Configure and Setup the MySQL database connection using PDO.
Part-2: Create a MySQL Database and a table using PDO.
Part-3: Insert record using prepared statement in PDO.
Part-4: Display Records using prepared statement.
Part-5: Search records using AJAX and PDO in PHP.
Part-6: Update Record using prepared statement in PDO.
Part-7: Delete Record using prepared statement in PDO.
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2015
(13)
-
▼
July
(8)
- PHP-Delete Record using prepared statement in PDO
- PHP - Update Record using prepared statement in PDO
- PHP - Search records using AJAX and PDO
- Part-4: Display Records using prepared statement
- PHP insert update, delete using PDO part-3
- PHP insert update, delete using PDO part-2
- PHP insert update, delete using PDO part-1
- PHP PDO : insert, update delete example for beginners
-
▼
July
(8)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
1 comments:
Being a developer I believe handling database is the most important aspect and if you’re good in database you’re best. Thanks for these queries as they are always needed!
Post a Comment