Professional Documents
Culture Documents
$sql = "SELECT *
FROM staff_tb
If you want to display the name of the office and the name of the branch separately, you can modify
your query to select the name field from both tables using aliases. Here's an example:
bash
Copy code
$sql = "SELECT
staff_tb.*,
designation_tb.name AS designation_name,
office_tb.name AS office_name,
office_branch_tb.name AS branch_name
FROM staff_tb
In this query, we are selecting all fields from the staff_tb table and also selecting the name fields
from the designation_tb, office_tb, and office_branch_tb tables using aliases (designation_name,
office_name, and branch_name). We are also joining the office_tb table to get the name of the
office.
You can then use these aliases in your PHP code to display the names separately. For example:
php
Copy code
This will display the name of the office and the name of the branch separated by a hyphen.
Dogan Robert
If you want to select data based on a specific column from multiple tables, you can add a WHERE
clause to your SQL query. Here's an example:
bash
Copy code
$sql = "SELECT
staff_tb.*,
designation_tb.name AS designation_name,
office_tb.name AS office_name,
office_branch_tb.name AS branch_name
FROM staff_tb
In this example, we are selecting data from the staff_tb, designation_tb, office_tb, and
office_branch_tb tables based on the condition that the active column in the staff_tb table is equal
to 1. You can replace staff_tb.active = 1 with any condition that you want to use to filter the data.
Note that in this query, we are still selecting all fields from the staff_tb table and the name fields
from the other tables using aliases. You can modify the query and the aliases based on your specific
needs.
$sql = "SELECT
staff_tb.id,staff_tb.first_name,staff_tb.middle_name,staff_tb.last_name,staff_tb.mobile,staff_tb.pf_
no,staff_tb.email,staff_tb.photo,staff_tb.Regdate,staff_tb.status,staff_tb.password,staff_tb.designati
on_id,staff_tb.office_branch_id,designation_tb.name as designation_name,office_branch_tb.name
as branch_name,office_tb.name AS office_name
FROM staff_tb
INNER JOIN office_branch_tb ON staff_tb.office_branch_tb_id =office_branch_tb.id
FROM staff_tb