Reads data from a table.
mixed db_get_data(string tablename [, mixed id [, mixed col [, string where [, int type [, string idfield [, string orderby]]]]]])
The table below summarizes the options for id and col.
| id |
col |
Data returned |
|---|---|---|
|
integer |
null |
Array with the whole record id |
|
integer |
string |
The value of column col of record id |
|
integer |
string array |
Array with column values in array col of record id |
|
integer array |
null |
Array of arrays with values from all columns of the id records |
|
integer array |
string |
Array with the values of column col from the id records |
|
integer array |
string array |
Two-dimensional array with the values of columns col from the id records |
|
null |
null |
Array of arrays with the whole table |
|
null |
string |
Array with values of the col column from the whole table |
|
null |
string array |
Array of arrays with the values of the columns col from the whole table |
The result type specifies which type of data you want to return. There are three possible types:
// Open database
db_open_database("sample.db");
// Read data from user whose identifier is 53
wb_set_text(wb_get_control($mainwin, ID_USER), db_get_data("user", 53));
// Fill up a list box with all user names
wb_set_text(wb_get_control($mainwin, ID_USERS), db_get_data("user", null, "name"));
// Display all users that are over 18 in a ListView
$itemlist = wb_get_control($window, ID_USERLIST);
$fields = array("id","name","phone","address");
$item_data = db_get_data("user", null, $fields, "age > 18");
wb_set_text($itemlist, $fields);
wb_create_items($itemlist, $item_data, true);