Sort Order

N

Netric

Guest
when displaying the search results (or all records) of a table, how can I sort by alphabetic order instead of the defautl order?

Thanks
 
K

Kristen

Guest
I was playing around with this, trying to get it to work, and I think this does it:

on form.php set the variable order to the field you want it to order by. In my case I did:

$order = "lastname";

I put it right before the switch statement in form.php that starts like:
switch($function){

If you put it at the beginning of the file it doesn't work, so be sure to put it right above the switch statement.

I am not a programmer or anything, so if this doesn't work I'm sorry!

Kristen
 
D

David Fannin

Guest
Here's one way to create a default sort order for show_all searches. I researched this a bit, and found that the default order for MySQL database tables are implementation dependent (i.e. there is no consistent default order). Therefore, I hacked the code a bit by creating a field in "dadabik_table_list" called "default_order" (varchar(50) not null no default value), and used it to specifiy a default sort for a table during show_all searches.

Here are the changes (in verson 2.2.1 beta):

1) add a field to dadabik_table list called "default_order".
varchar(50) not null no default value

2) add the order by clause you want into the "default_order" field


2) add the following to form.php, starting on line 263, replacing the if order test :

if ($order != ""){
$sql .= " order by ".$quote.$order.$quote;
} elseif ( ($default_order=default_table_order($conn,$table_name)) != "" ) {
$sql .= " order by ".$default_order." ";
}
// end if

3)
 
D

David Fannin

Guest
Here's one way to create a default sort order for show_all searches. I researched this a bit, and found that the default order for MySQL database tables are implementation dependent (i.e. there is no consistent default order). Therefore, I hacked the code a bit by creating a field in "dadabik_table_list" called "default_order" (varchar(50) not null no default value), and used it to specifiy a default sort for a table during show_all searches. Its a start towards fixing the default order problem, but it needs some work to be a full blown feature. In particular, it needs to be added to the admin menu, to make changes to the default_order field via the admin interface. Note that this is a bit of a hack, and I have not done any real testing or verification that it doesn't break something else. Please use it at your own risk!


Here are the changes (in verson 2.2.1 beta):

1) add a field to dadabik_table list called "default_order".
varchar(50) not null no default value

2) add the order by clause you want into the "default_order" field:
example: if you want to default order to be by field "lastname", then
enter "lastname", if you want multiple fields, then enter them: "lastname , firstname".


2) change the following to form.php, starting on line 263, replacing the if order test :

if ($order != ""){
$sql .= " order by ".$quote.$order.$quote;
} elseif ( ($default_order=default_table_order($conn,$table_name)) != "" ) {
$sql .= " order by ".$default_order." ";
}
// end if

3) add the following function to include/business_logic.php, after line 1847.
This addes a new function, default_table_order, that lookups if a table has a default_order list.

function default_table_order($conn, $table_name)
// goal: get the default table order
// input: $table_name
// output: default order by clause or blank
{
global $table_list_name, $db_name, $quote;
if (table_exists($db_name, $table_list_name)){
$sql = "select ".$quote."default_order".$quote." from ".$quote."$table_list_name".$
quote." where ".$quote."name_table".$quote." = '$table_name'";
$res_order = execute_db("$sql", $conn);
if (get_num_rows_db($res_order) == 1){
$row_order = fetch_row_db($res_order);
$order_table = $row_order[0];
if ($order_table == ""){
return "";
} // end if
else{
return $order_table;
} // end else
} // end if
elseif (get_num_rows_db($res_order) == 0){ // e.g. I have an empty table
return "";
} // end elseif
else{
exit;
} // end else
} // end if
else{
return "";
} // end else
} // end function default_table_order()

4) thats it. You should now be able to do a show_all search from anywhere in Dadabik, and it should use the default_order for that particular table.



I should note that this code needs improvement in several areas. Folks should feel free to hack this code to fix it.

improvements needed:

1) testing to make sure it hasn't broken anything.
2) add code to make the default order field changable via the admin interface.
3) automatic update to the default_order field if the underlying table field is deleted or modified.
 
Top