ptb_map
Returns whole first record for which $equation is met. If $otherFieldname is given, only value of this field is returned.
Syntax
Syntax description
- $database
- variable containing connected database
- $equation
- condition upon which record should be selected, in the form 'fieldname' == 'value'
- $otherFieldname
- optional: name of other field, which value you look for
Return
This function returns array or, if $otherFieldname was given, string. If nothing was found, null is returned.
Sample(s)
The above example finds value of age field of the record, for which id field equals to 5.
This function is useful, when you know value of id (usually as $_GET['id']) and want to find value of other field of this particular record. Notice that you can't just use id as the number of the record in the database (precisely speaking, you could try to use id-1 as this number), since ids will not always be consecutive natural numbers (could be sorted, deleted etc.).
Update: if id is your primary key, it's much faster and convenient to use ptb_connect with id as $keyField–this way you won't need to use ptb_map at all!
ptb_map is faster then ptb_select with $limit 1.