(PHP 4 CVS only)
dbx_cmp_asc -- Compare two rows for sorting in ascending order
Description
int dbx_cmp_asc
(array row_a, array row_b, string columnname_or_index [, int
comparison_type])
Returns 0 if row_a[$columnname_or_index] is equal to
row_b[$columnname_or_index], 1 if it is greater and -1 if it is
smaller.
The comparison_type parameter can be used
to force a numeric compare (by setting it to DBX_CMP_NUMBER). The default
comparison is by text (e.g. "20" is greater than "100").
Example 1. dbx_cmp_asc() example
<?php
function user_re_order ($a, $b) {
$rv = dbx_cmp_desc ($a, $b, "parentid");
if (!$rv) {
$rv = dbx_cmp_asc ($a, $b, "id");
return $rv;
}
}
$link = dbx_connect ("odbc", "", "db", "username", "password")
or die ("Could not connect");
$result = dbx_query ($link, "SELECT id, parentid, description FROM tbl ORDER BY id");
echo "resulting data is now ordered by id<br>";
dbx_sort ($result, "user_re_order");
echo "resulting data is now ordered by parentid (descending), then by id<br>";
dbx_close ($link);
?>
|
|
See also dbx_sort() and
dbx_cmp_desc().