Deprecated
This function is deprecated and we recommend using the DB:Query() function from Database API.
Selects records from the database, sorts the data by the orderby field(s), and returns the recordset.
Syntax
Query(where, orderby)
Arguments
where
a WHERE clause. Example: "ID=19".
orderby
one or more fields used to sort the recordset by.
Return value
Returns the recordset on success or FALSE on error.
Example 1
Select all records where name contains 'Jim'. To fetch a returned row as an associative array use db_fetch_array function.
dim tblUsers, rs
set tblUsers = dal.Table("UsersTable")
doAssignmentByRef rs, tblUsers.Query("Name like '%Jim%'","Email DESC")
do while bValue(DoAssignment(data,db_fetch_array(rs)))
response.write data("fieldName") & "<br>"
loop
Note: the db_fetch_array function is deprecated, and we recommend using the fetchAssoc function instead.
The corresponding SQL query:
select * from UsersTable where Name like '%Jim%' order by Email DESC
Example 2
Select and print all orders for John Sample. To fetch a returned row as an associative array, use the db_fetch_array function.
dim tblOrders, rs
set tblOrders = dal.Table("OrdersTable")
doAssignmentByRef rs, tblOrders.Query("Customer='John Sample'","OrderID DESC")
do while bValue(DoAssignment(data,db_fetch_array(rs)))
response.write "Order " & data("OrderID") & " was placed " & data("OrderDate") & " by " & data("Customer") & "<br>"
loop
Note: the db_fetch_array function is deprecated, and we recommend using the fetchAssoc function instead.
The corresponding SQL query:
select * from OrdersTable where Customer like 'John Sample'
order by OrderID DESC
Examples:
•Example: Show data from master table on details view/edit/add page
•Example: Before deleting a record check if related records exist
•Example: Redirect to user info edit page
•Example: Show list of customer orders
See also:
•QueryResult object: fetchAssoc