This topic is locked

Help with dependant dropdown

5/11/2012 2:46:35 PM
PHPRunner General questions
W
wildwally author

I'm not sure if it's even possible - from my search I think it might be just not sure if PHP Runner has any limits, so here it is.
I have the dependant dropdown working in a simple fashion, when field1 is choosen field2 reflects the data according to the item selected in field1. I however, need the data exploded into options for the user to select. My data is in an array "2,8,22,34" I want the field2 dropdown to show options like
<Option>2</Option>

<Option>8</Option>

<Option>22</Option>

<Option>34</Option>
instead of the <Option>2,8,22,34</Option> that it does now. These numbers relate to ID numbers in another table that my ultimate target would be to translate the ID's to the descriptions. But I just want to see if this is possible first.

C
cgphp 5/11/2012

Add a new field to the details table that points to the master table.
Example:
details_table

id | master_id

2 | 5

8 | 5

22 | 5

34 | 5

60 | 6

59 | 6


It will be more easy to link the two tables without the need to explode data values.

W
wildwally author 5/11/2012



Add a new field to the details table that points to the master table.
Example:
details_table

id | master_id

2 | 5

8 | 5

22 | 5

34 | 5

60 | 6

59 | 6


It will be more easy to link the two tables without the need to explode data values.


I understand perfectly what you are saying and even considered this direction; however, the work required to maintain the data in this format/fashion would not be acceptable.

C
cgphp 5/11/2012

I'm afraid you can't use the native dependent dropdowns if your data are organized in this manner.

W
wildwally author 5/11/2012

Ok, can you provide some guidance as to how to just change the values in the dropdown before display or load of the page? I have other instances of exploding data arrays within my site that I can reference, maybe the alternative would be to have the user select a couple of options up fron tthen based on those option run a series of data queries and explodes to build the next page.

Sergey Kornilov admin 5/12/2012

Unfortunately it doesn't work this way.
The best you can do is to move all logic to Javascript, parsing data and populating dropdown boxes there. This requires pretty heavy coding though.

W
wildwally author 5/14/2012



Unfortunately it doesn't work this way.
The best you can do is to move all logic to Javascript, parsing data and populating dropdown boxes there. This requires pretty heavy coding though.


I was succesful in getting a dropdown to populate with my data through the use of a PHP snippet and here is the code.

<code>
//create dropdown box
$str = "";
$str.= "<select name=\"shelf_kit\" id = \"shelf_kit\">";
//select values from database
global $conn;
$strSQL = "select Shelf_Kit_List from dbo.QQ_CASE_CASES WHERE Model_Number = '".$_SESSION['CModel']."'";

$rs = db_query($strSQL,$conn);

$data = db_fetch_array($rs);
$SQuery = "SELECT Kit_Number, Description FROM dbo.QQ_CASE_Kits WHERE ID IN (".$data['Shelf_Kit_List'].")";

$results = db_query($SQuery,$conn);

//$data1 = db_fetch_array($results);
//$dropdown_data = explode(",", $data1['Kit_Number'] + ' ' + $data1['Description']);

$str.="<option value=''>Please Select</option>";

//foreach($data1 as $key => $value)

while($data1=db_fetch_array($results))

{

$str.="<option value='".$data1['Kit_Number']."'>".$data1['Description']."</option>";

}

$str.="</select>";

echo $str;
</code>
Now to get PHPRunner to utilize and work with the field? I've found instructions in the manual regarding custom fields to submit the data. But I'm not having any luck getting the js to read the value fo the field. I was trying to cheat the system to copy the user selected value into a PHPR generated field so that the dependant drop downs would work as usual for the remain fields. Or get the dependant drop down setup to recogonize the custom field. There has got to be some happy medium in all of this...

Sergey Kornilov admin 5/14/2012

Unfortunately you won't be able to make dependant drop down setup to recogonize the custom field. It's just not possible.
The best workaround is to use the data structure explained by Cristian. To reduce maintenance hurdles you can use a custom control there, displaying data from multiple table records as a single control and saving them back to the database manually.

W
wildwally author 5/14/2012



Unfortunately you won't be able to make dependant drop down setup to recogonize the custom field. It's just not possible.
The best workaround is to use the data structure explained by Cristian. To reduce maintenance hurdles you can use a custom control there, displaying data from multiple table records as a single control and saving them back to the database manually.


Ok, looking at it from the suggestions Cristian and you offer. If I have the user multiselect the option associated with the item and save each instance back to the database as a single item. Can you provide example of the foreach item to be saved code? Reading this doesn't make sense so I'll try to clarify.
If the user selects 4 options that pertain to the item, I would then need each option to be saved to the database as a line item. Example or link to how this is done?

Sergey Kornilov admin 5/14/2012
W
wildwally author 5/14/2012



This example can help:

http://xlinesoft.com...iple_values.htm


Thanks, I was headed down that direction after thinking things through. Glad to know that I'm getting to know the in's and out's of PHPR better. I'll keep you posted as it pans out.