DMXzone Database Connector Manual

March 17, 2016
Sorting Database Query Results
Sorting Database Query Results

With this movie we will show you how to sort database query results, on your page.

Step by Step

We will show you how to sort database query results, on your page. We created a database query, as well as repeat region, where we list our products. Note: please check our previous tutorials in order to learn how to setup a database connection query and repeat regions on your page. Our query returns our products, unsorted (1). First, we need to create a variable, that will be used later, to sort the results. Right click get. And add a new variable. We call this variable sort (2). Save your action file (3). Then, select your database query (4). And click the query options button. Open the sort options tab (5). We want to sort our query by product name, so we add the product name column to the sord order list (6). We select ascending order, for this column. Now, we are going to apply a condition, when this sort order should be applied. Select the server data bindings button, for the condition.

And under Globals get select the variable, that we created earlier. Now, let's define the condition (1). We want the ascending sort order to be applied, when this variable has a value of ascending. So we add equals to ascending. Note, the word ascending must be surrounded by single quotes (2). Click the select button (3).

Now, we add the product name column once again, to the sort order list (1). This time, we select descending order (2). Click the server data bindings button, for the condition, when descending order must be applied.

And under globals get select the sort variable, that we created (1). Go into the expression field and add equals to descending, surrounded by single quotes. equals to descending, surrounded by single quotes (2). And then click the select button.

Click OK. And save your server action (1). Now, we are going to add two buttons, that will be used to control the sort order. Open the insert menu. And under form select button (2). Let's call this button sort ascending (3).

We add another button, and call it - sort descending. Select the ascending button (1). And click the add new behavior button, in the behaviors panel. Select DMXzone. then click - control dmxzone server connect action executor (2). Select - run, in the action dropdown. And select your server action executor, which you are using to display the query results on the page (3).

Here, you will see the get variable that we created in the beginning (1). Let's add a value to it, so it sorts the query by ascending order. According to the condition, which we set in the query sort tab, we should enter ascending in this field (2). Click the ok button.

Now, our query will be sorted by ascending order, when the sort ascending button is clicked. We do the same for the descending button this time we enter descending as a value for our variable. Let's preview the final results.

That's how easy it is to sort your query results, using simple html buttons.