Firefox 3
Quick navigation:

ptb_select

Selects records up to $limit from connected database according to given condition and optionally sorts them.

Syntax

$var = ptb_select($database, $condition[, $sort = ''[, $limit = '']]);

Syntax description

$database
variable containing connected database
$condition
condition upon which records should be selected
$sort
optional: how records should be sorted (sorting on multiple columns allowed)
$limit
optional: how many records meeting given condition should be picked up (if no $limit is given, all such records will be selected)

Return

This function returns array or null, if nothing has been selected.

Sample(s)

$x = ptb_select($myDatabase, "'age' > 40", 'birth DESC'); $x = ptb_select($myDatabase, "'age' > 40 AND 'sex' == 'M'", 'name ASC, birth DESC'); $x = ptb_select($myDatabase, "even('age')"); $x = ptb_select($myDatabase, "'name' == '{$_GET['name']}'"); $x = ptb_select($db_test, "'id' == '{$db_test1[1]['price']}'");

Tips

Order of $limit and $sort arguments doesn't really matter; if you want to set only $limit, you can simply use:

$x = ptb_select($myDatabase, "even('age')", 10);

If value of multidimensional table is to appear in $condition, use {} to surround the expression (see the last example above; braces were rendered bold to increase visibility).

If you need only one record, always use $limit = 1 to speed up the function.

If you need all the records, you needn't use ptb_select at all, since the variable you used to connect to the data file already contains them!

If you want to find value of one (unique or just first) field of a record, in which another field is equal to a given value, you should use ptb_map instead.

If you want to search the database for records containing specified text in certain field, eg. author, you can use eregi() function:

$x = ptb_select($myDatabase, "eregi('text_to_look_for', 'author')");