record_get()

Fetch one record from a table by its id.

Syntax

record_get(table, id)

Parameters

Name Type Required Description
table string or number yes The table's name, its database table name, or its numeric table id. Read the id from $table at run time (for example $table["fields"]["client"]["lookup_table"]); never type one into your code, because table ids change when a workspace is copied. A table whose name happens to be a number always wins over the table with that id.
id int yes The record's primary key.

Returns

The record as an array (fields keyed by field id, plus _meta), or null if no record with that id exists.

Example

$deal = record_get("deals", $record["_meta"]["id"]);
if ( $deal ) {
    sys_log("Stage: " . $deal["stage"]);
}

Example output

[
    "name" => "Acme renewal",
    "stage" => "negotiation",
    "amount" => 12000,
    "_meta" => ["id" => 87, "title" => "Acme renewal"]
]

Notes

  • Returns null rather than throwing when the record is missing — always check before using the result.
  • To fetch many records, use records_query().

See also: record_update(), records_query()