i
PHP Variables
PHP Data Types
PHP Echo & Print
PHP Strings
PHP Numbers
PHP Constants
PHP Operators
PHP if...else...elseif Statements
Switch Statement
PHP Loops
PHP Arrays
Superglobals
PHP Coding Standards
PHP Form Handling
PHP Form Validation
PHP URLs Validation
PHP Form Required Validation
Complete Form Example
PHP File Functions Open/Read
PHP File Create/Write
PHP File Upload
PHP Cookies Handling
PHP Session Handling
PHP filter_var() Function
PHP Validation Filters
PHP Sanitization Filters
Using Filters
Filters Advanced
JSON
PHP Date and Time
MySQL Database
MySQL Connect
MySQL Commands-Creating a Table
MySQL Commands-Inserting The data
MySQL Commands-Prepared Statement
MySQL Commands-Selecting The Data
MySQL Commands-Where and Order By
MySQL Commands-Deleting And Updating The Data
PHP-OOP Introduction
PHP-Classes/Objects
PHP-Constructor/Destructor
PHP-Access Modifiers
PHP-Inheritance
PHP-Inheritance and Protected Access Modifier
PHP-Overriding Inherited Methods
PHP-Final keyword
PHP-Abstract Classes
PHP-Constants
PHP-Traits
PHP-Static Methods and Properties
Introduction to Functions
Defining A function
Returning Values From A Function
Dynamic Function Calls
Variable Scope
Understanding Arguments Or Parameters
Testing For A Function Existence
Returning Multiple Values From A Function
Making practical Use By Building Code Libraries For Code Re-usability
Using Include() And Require()
You have two options to select or view data in SQL. You can either select all the columns or select only required columns to see the data. For both the options you need to use SELECT statement. To view the data use below syntax.
SELECT column1, column2,… from table_name
or
SELECT * from table_name //To select all the columns
You can use the SELECT command in php as below:
$server_name = "localhost";
$username = "username";
$password = "password";
$db_name = "my_project";
$conn = new mysqli($server_name, $username, $password, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT visitor_id, name, email FROM Visitors";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["visitor_id"]. " - Name: " . $row["name"]. "
" . Email $row["email"]. "
";
}
} else {
echo "0 results";
}
$conn->close();
?>
You can also LIMIT the data to choose how many records you want to see. For example, if you want to see only 20 records you can write the below statement.
SELECT * FROM Visitors LIMIT 20;
If you want to see the data for 5 visitors after 20th record then you can use OFFSET as below:
SELECT * FROM Visitors LIMIT 5 OFFSET 20;
Don't miss out!