Please enable JavaScript to view this site.

Navigation: » No topics above this level «

DAL method: Query (Deprecated)

Scroll Prev Next More

 

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.

 

dynamic tblUsers= GlobalVars.dal.Table("UsersTable");
XVar rs = tblUsers.Query("Name like '%Jim%'","Email DESC");
XVar data;
while(data = CommonFunctions.db_fetch_array(rs))
{
  MVCFunctions.Echo(data["fieldName"].ToString() + "<br>");
}

 

Note: the db_fetch_array function is deprecated, and we recommend using the fetchAssoc function instead.

 

The corresponding SQL query:

 

select * from carsmodels where Make like '%Vol%' order by Model DESC

Example 2

Select and print all models for Audi.  To fetch a returned row as an associative array, use the db_fetch_array function.

 

dynamic tblCarsModel = GlobalVars.dal.Table("carsmodels");
XVar rs = tblCarsModel.Query("Make='Audi'", "Model DESC");
XVar data;
while (data = CommonFunctions.db_fetch_array(rs))
{
  MVCFunctions.Echo("Order " + data["model"].ToString() + " was produced by " + data["make"].ToString() + "<br>");
}

 

Note: the db_fetch_array function is deprecated, and we recommend using the fetchAssoc function instead.

 

The corresponding SQL query:

 

select * from carsmodels where Make like 'Audi'
order by Model 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

DAL Method: QueryAll

DAL Method: CustomQuery

DB API: Query

Database API

About Data Access Layer