Skip to main content
Topic: lookup field (Read 3778 times) previous topic - next topic

lookup field

Suppose you have a data table 'customers'. Those customers have a property: nationality . To have users make similar choices, we can use a select with certain values as index and a description as text. I want to store an integer only, so not the text, in the customer table field nationality. I create another table: nationalities. There i store an ID and a descrpition. In the add and edit customer pages, i want the select filled with the index/value from the table nationality. In the other customer pages i want to see only the text, not the index.

EG both 'php generator for mysql'  and 'Code Charge Studio' have a standard field option called 'Lookup field'.

How can we do this in PHP Rad?


Re: lookup field

Reply #2
@MarkTimmer
This is how you archive same result in PhpRad:
In the attachment below steps have been labeled from from 1 to 10 which i will reference them later on.

1. First thing you need to do is click on the add page or edit page of the tables field you want to work on, mine is "post". NOTE: Any changes made to the Add Page reflects in the Edit Page and vise versa.
2. Next you have to click on the FieldName you want to work on, mine is "posted_by".
3. Next, you set the Field Properties to Select.
4. Next, click the button at the extreme right of OptionListDataSource. A popup window comes up(like image 2.png below).
5. Click on Data Table.
6. Select the table you want to get data from to populate your select field. Mine is "user", yours would be nationalities.
7. Select the field that contains the data you want to store as value when an item is selected from the select field, mine is id. this is the field that holds the data you want to store in the nationality of a customer.
8. Select the field that contains the data that would be displayed to the end-user eg. nationalities. mine was user names.
10. Select the field you want the query to use in sorting the list of nationalities, mine is name.
9. Select how you want the field in step 10 should be ordered, DESC (Descending) or ASC (Ascending).

And there are other advance settings below like Remote Search Lookup and Dynamic Select Lookup.
if you want to do a remote lookup while end-user types, you select Remote Search Lookup and if you want the current select field to depend on the input from another field, then select the Dynamic Select Lookup and set the matching field and the input field it depends on.

then you click the okay button and go preview the changes, enjoy.😎

Re: lookup field

Reply #3
Thanks for the help. But this is exactly what i did, without the right result but with the result i described, so please check if in the latest download version this still functions properly. Because i did tyhis exactely in the example i documented in the forum i use the table generators and not nationalities. The table has an ID and a name. I fill in the form exactely as you describe and in the add page i get something that looks right, but if i use chrome inpect i see that the options look like this <option value="$name">$name</option>, so the value, or ID from the table dissapeared. Selecting this i want to add a record in the table klanten with the value generator, being the selected value of the selected option. As this is, because of what i call a bug (specially now i know i set the right steps) it tries to store the label:$name. So it stores null. In the edit page the select has the same problem and besides it ads a first option with the value of generator from the first record of klanten. If its not clear, tell me ill make a recording of what i am doing.

Re: lookup field

Reply #4
The weird thing, in the newer version PHPRAD Vue, iy works ok!

 

Re: lookup field

Reply #5
@MarkTimmer I don't see the error you talk about in mine. below attachment is the view and the html code, i see the id display as value which is 1 and the name display as label, which is willvin.

1. please make sure you are using the latest version of PhpRad Classic.
2. If you are using the latest version , which is 2.5.1, please create a new project and follow my previous instruction.
3. if it still doesn't work, please let me know so that i can create a working example for you to check from your end.