<HTML ><HEAD ><TITLE >dbx_compare</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual de PHP" HREF="index.html"><LINK REL="UP" TITLE="dbx functions" HREF="ref.dbx.html"><LINK REL="PREVIOUS" TITLE="dbx_close" HREF="function.dbx-close.html"><LINK REL="NEXT" TITLE="dbx_connect" HREF="function.dbx-connect.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual de PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.dbx-close.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.dbx-connect.html" ACCESSKEY="N" >Siguiente</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.dbx-compare" ></A >dbx_compare</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN13016" ></A ><P > (PHP 4 >= 4.1.0)</P >dbx_compare -- Compare two rows for sorting purposes</DIV ><DIV CLASS="refsect1" ><A NAME="AEN13019" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >dbx_compare</B > ( array row_a, array row_b, string column_key [, int flags])<BR ></BR ><P > <B CLASS="function" >dbx_compare()</B > returns <TT CLASS="literal" >0</TT > if the <TT CLASS="literal" >row_a[$column_key]</TT > is equal to <TT CLASS="literal" >row_b[$column_key]</TT >, and <TT CLASS="literal" >1</TT > or <TT CLASS="literal" >-1</TT > if the former is greater or is smaller than the latter one, respectively, or vice versa if the <TT CLASS="parameter" ><I >flag</I ></TT > is set to <TT CLASS="constant" ><B >DBX_CMP_DESC</B ></TT >. <B CLASS="function" >dbx_compare()</B > is a helper function for <A HREF="function.dbx-sort.html" ><B CLASS="function" >dbx_sort()</B ></A > to ease the make and use of the custom sorting function. </P ><P > The <TT CLASS="parameter" ><I >flags</I ></TT > can be set to specify comparison direction: <P ></P ><UL ><LI ><P > <TT CLASS="constant" ><B >DBX_CMP_ASC</B ></TT > - ascending order </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_CMP_DESC</B ></TT > - descending order </P ></LI ></UL > and the preferred comparison type: <P ></P ><UL ><LI ><P > <TT CLASS="constant" ><B >DBX_CMP_NATIVE</B ></TT > - no type conversion </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_CMP_TEXT</B ></TT > - compare items as strings </P ></LI ><LI ><P > <TT CLASS="constant" ><B >DBX_CMP_NUMBER</B ></TT > - compare items numerically </P ></LI ></UL > One of the direction and one of the type constant can be combined with bitwise OR operator (|). The default value for the <TT CLASS="parameter" ><I >flags</I ></TT > parameter is <TT CLASS="constant" ><B >DBX_CMP_ASC</B ></TT > | <TT CLASS="constant" ><B >DBX_CMP_NATIVE</B ></TT >. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN13069" ></A ><P ><B >Ejemplo 1. <B CLASS="function" >dbx_compare()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" ><?php function user_re_order ($a, $b) { $rv = dbx_compare ($a, $b, "parentid", DBX_CMP_DESC); if ( !$rv ) { $rv = dbx_compare ($a, $b, "id", DBX_CMP_NUMBER); } return $rv; } $link = dbx_connect (DBX_ODBC, "", "db", "username", "password") or die ("Could not connect"); $result = dbx_query ($link, "SELECT id, parentid, description FROM table ORDER BY id"); // data in $result is now ordered by id dbx_sort ($result, "user_re_order"); // date in $result is now ordered by parentid (descending), then by id dbx_close ($link); ?></PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > See also <A HREF="function.dbx-sort.html" ><B CLASS="function" >dbx_sort()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.dbx-close.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Inicio</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.dbx-connect.html" ACCESSKEY="N" >Siguiente</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >dbx_close</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.dbx.html" ACCESSKEY="U" >Subir</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >dbx_connect</TD ></TR ></TABLE ></DIV ></BODY ></HTML >