From 8fdd2e80b1466dc6646d9d74addd1af3655cc587 Mon Sep 17 00:00:00 2001 From: Marc Boeren Date: Wed, 18 Apr 2001 12:39:17 +0000 Subject: [PATCH] Fixed examples for dbx_sort, dbx_cmp_asc and dbx_cmp_desc. Added the optional comparison_type parameter to dbx_cmp_asc and dbx_cmp_desc (Mc) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@45469 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/dbx.xml | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/functions/dbx.xml b/functions/dbx.xml index f666adc915..299d1b86df 100644 --- a/functions/dbx.xml +++ b/functions/dbx.xml @@ -391,7 +391,7 @@ dbx_close($link); <?php function user_re_order ($a, $b) { - $rv = dbx_cmp_asc ($a, $b, "parentid"); + $rv = dbx_cmp_desc ($a, $b, "parentid"); if (!$rv) $rv = dbx_cmp_asc ($a, $b, "id"); return $rv; } @@ -400,8 +400,8 @@ $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_query ($result, "user_re_order"); -echo "resulting data is now ordered by parentid, then 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); ?> @@ -426,6 +426,9 @@ dbx_close ($link); array row_a array row_b string columnname_or_index + int + comparison_type + @@ -433,12 +436,17 @@ dbx_close ($link); 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"). + <function>dbx_cmp_asc</function> example <?php function user_re_order ($a, $b) { - $rv = dbx_cmp_asc ($a, $b, "parentid"); + $rv = dbx_cmp_desc ($a, $b, "parentid"); if (!$rv) { $rv = dbx_cmp_asc ($a, $b, "id"); return $rv; @@ -449,8 +457,8 @@ $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_query ($result, "user_re_order"); -echo "resulting data is now ordered by parentid, then 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); ?> @@ -474,8 +482,9 @@ dbx_close ($link); int dbx_cmp_desc array row_a array row_b - string - columnname_or_index + string columnname_or_index + int + comparison_type @@ -484,12 +493,17 @@ dbx_close ($link); 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"). + <function>dbx_cmp_desc</function> example <?php function user_re_order ($a, $b) { - $rv = dbx_cmp_asc ($a, $b, "parentid"); + $rv = dbx_cmp_desc ($a, $b, "parentid"); if (!$rv) { $rv = dbx_cmp_asc($a, $b, "id"); return $rv; @@ -500,8 +514,8 @@ $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_query ($result, "user_re_order"); -echo "resulting data is now ordered by parentid, then 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); ?>