A
alpha2zee
Guest
DaDaBik allows one to fill the select_single pull down menu with options that are from values in a foreign table. The problem is, it shows all items from the table. I want to be able to selectively choose from the foreign table. So here is my fix (confirmed for version 3.2 beta).
Idea
----
Create new field named 'linked_fields_extra_mysql' for the dadabik_tables which can be used to pass 'WHERE' clauses in the MySQL query
How
----
1. If you already have DaDaBik installed - meaning DaDaBik has been run once atleast, as a result of which all the dadabik_ tables have been generated in the database:
Using something like phpmyadmin or Navicat, create a new field in all of the dadabik_ tables with these parameters -
linked_fields_extra_mysql
varchar(255)
not null
utf-8_general_ci
This is not needed if you have not run DaDaBik yet.
2. Edit include/internal_table.php
Add at end:
$int_fields_ar[25][0] = "Extra for MySQL statement:";
$int_fields_ar[25][1] = "linked_fields_extra_mysql";
$int_fields_ar[25][2] = "text";
$int_fields_ar[25][3] = "25";
3. Edit admin.php
Look for:
$linked_fields_order_type_field_temp = addslashes($fields_labels_ar[$j]["linked_fields_order_type_field"]);
Below it, add:
$linked_fields_extra_mysql_temp = addslashes($fields_labels_ar[$j]["linked_fields_extra_mysql"]);
Look for:
".$quote."linked_fields_order_type_field".$quote."
After the last double-quote mark, add (note the first comma):
,".$quote."linked_fields_extra_mysql".$quote."
Look for:
'$linked_fields_order_type_field_temp'
At end of that, add (note the first comma):
,'$linked_fields_extra_mysql_temp'
4. Edit include/business_logic.php
Go to function build_fields_labels_array($table_internal_name, $order) and look for:
".$quote."linked_fields_order_type_field".$quote.",
After that, add:
".$quote."linked_fields_extra_mysql".$quote.",
Scroll down to look for:
$fields_labels_ar[$i]["linked_fields_order_type_field"] = $field_row["linked_fields_order_type_field"]; // the order type (ASC|DESC) to use in the order clause when retreiving the linked fields
Below that, add:
$fields_labels_ar[$i]["linked_fields_extra_mysql"] = $field_row["linked_fields_extra_mysql"]; // extra MySQl command to use when retrieving the linked fields
Go to function build_form($table_name, $action, $fields_labels_ar, $form_type, $res_details, $where_field, $where_value) and look for:
$sql .= " FROM ".$quote.$primary_key_table_field.$quote;
Below, add:
// extra mysql clauses
if ($linked_fields_extra_mysql != "")
{$sql .= $linked_fields_extra_mysql;}
Go to function create_internal_table($table_internal_name) and look for:
linked_fields_order_type_field VARCHAR(255) NOT NULL,
Add after that:
linked_fields_extra_mysql VARCHAR(255) NOT NULL,
Using
-----
Now when you configure fields for tables, you will see a field 'Extra for MySQL statement.' It can be filled with something like
WHERE `status` = 'Current'
Now, the pull down menu will be filled with values from the foreign table only if the above condition is satisfied.
Help
----
I have not extensively tested this. Please correct any bugs in this forum.
Idea
----
Create new field named 'linked_fields_extra_mysql' for the dadabik_tables which can be used to pass 'WHERE' clauses in the MySQL query
How
----
1. If you already have DaDaBik installed - meaning DaDaBik has been run once atleast, as a result of which all the dadabik_ tables have been generated in the database:
Using something like phpmyadmin or Navicat, create a new field in all of the dadabik_ tables with these parameters -
linked_fields_extra_mysql
varchar(255)
not null
utf-8_general_ci
This is not needed if you have not run DaDaBik yet.
2. Edit include/internal_table.php
Add at end:
$int_fields_ar[25][0] = "Extra for MySQL statement:";
$int_fields_ar[25][1] = "linked_fields_extra_mysql";
$int_fields_ar[25][2] = "text";
$int_fields_ar[25][3] = "25";
3. Edit admin.php
Look for:
$linked_fields_order_type_field_temp = addslashes($fields_labels_ar[$j]["linked_fields_order_type_field"]);
Below it, add:
$linked_fields_extra_mysql_temp = addslashes($fields_labels_ar[$j]["linked_fields_extra_mysql"]);
Look for:
".$quote."linked_fields_order_type_field".$quote."
After the last double-quote mark, add (note the first comma):
,".$quote."linked_fields_extra_mysql".$quote."
Look for:
'$linked_fields_order_type_field_temp'
At end of that, add (note the first comma):
,'$linked_fields_extra_mysql_temp'
4. Edit include/business_logic.php
Go to function build_fields_labels_array($table_internal_name, $order) and look for:
".$quote."linked_fields_order_type_field".$quote.",
After that, add:
".$quote."linked_fields_extra_mysql".$quote.",
Scroll down to look for:
$fields_labels_ar[$i]["linked_fields_order_type_field"] = $field_row["linked_fields_order_type_field"]; // the order type (ASC|DESC) to use in the order clause when retreiving the linked fields
Below that, add:
$fields_labels_ar[$i]["linked_fields_extra_mysql"] = $field_row["linked_fields_extra_mysql"]; // extra MySQl command to use when retrieving the linked fields
Go to function build_form($table_name, $action, $fields_labels_ar, $form_type, $res_details, $where_field, $where_value) and look for:
$sql .= " FROM ".$quote.$primary_key_table_field.$quote;
Below, add:
// extra mysql clauses
if ($linked_fields_extra_mysql != "")
{$sql .= $linked_fields_extra_mysql;}
Go to function create_internal_table($table_internal_name) and look for:
linked_fields_order_type_field VARCHAR(255) NOT NULL,
Add after that:
linked_fields_extra_mysql VARCHAR(255) NOT NULL,
Using
-----
Now when you configure fields for tables, you will see a field 'Extra for MySQL statement.' It can be filled with something like
WHERE `status` = 'Current'
Now, the pull down menu will be filled with values from the foreign table only if the above condition is satisfied.
Help
----
I have not extensively tested this. Please correct any bugs in this forum.