SELECT
statement is used to select data from a database.
The next example performs the following tasks according to the selected option:
Enrollments
and Courses
if requested.
Enrollments
and Courses
if requested.
The SQL commands are given below:
CREATE TABLE Courses ( number CHAR( 10 ) PRIMARY KEY, name VARCHAR( 16 ) ) ENGINE=InnoDB; INSERT INTO Courses VALUES ('457','E-Commerce'), ('351','File Processing'); CREATE TABLE Enrollments ( name VARCHAR( 32 ), course CHAR( 10 ), PRIMARY KEY ( name, course ), FOREIGN KEY ( course ) REFERENCES Courses ( number ) ) ENGINE=InnoDB; INSERT INTO Enrollments VALUES ('Bart', '351'), ('Bart', '457'); INSERT INTO Enrollments SELECT 'Ben', number FROM Courses WHERE name = 'E-Commerce';
query
function to execute the SQL SELECT
command:
SELECT E.name student, C.name course FROM Enrollments E, Courses C where E.course like '%$course%' and E.course = C.number;
query
function in the $result
variable.
fetch_assoc( )
function to fetch a result row as an associative array.
fetch_assoc( )
returns the next row in the result rows.
$row
variable ($row['student']
and $row['course']
).
βIt takes a very long time to become young.β β Pablo Picasso |