Lookup on a non-primary key field
Posted: 2013-11-10 22:50
Please let me preface this with the fact that I am new to PHP and mysql. (I've used MSSQL and other languages some, but not these two.) So please forgive my ignorance for what is probably a very basic question.
I have a table called Category. In that table, there are about 4 fields. One is idCategory which is the primary key. I also have two other fields: categoryname and categorycolor. I want a look up that presents the user with the category name and color concatenated in the dropdown (e.g., Food - Orange) but I want to store the value of categoryColor into the field I'm populating.
I've tried editing the mysql statement in the lookup manually. But I'm a bit confused about how that statement works within appgini. I tried the following statement and it presents the right information to the user in the dropdown. However, in the edit view, it does not automatically select the right selection from the dropdown based on what is in the database. It defaults to the first in the list. Also, in the grid view, the field information in color field (the one I'm trying to populate) is blank, even though there is data in the field.
The good news is that the update portion is working fine. When I edit a record, if I select the color using the current dropdown, it does in fact update the record with the correct color in that field. It's just that it's not working properly for the grid view and the edit view.
Here's the current sql statement in my lookup in appgini: SELECT `category`.`CategoryColor`, IF(CHAR_LENGTH(`category`.`CategoryName`) || CHAR_LENGTH(`category`.`CategoryColor`), CONCAT_WS('', `category`.`CategoryName`, ' - ', `category`.`CategoryColor`), '') FROM `category` ORDER BY 2
Any help would be most appreciated! Athelene
p.s. I realize it's always better to use primary keys for this. However, the database was created by someone else and it's too late at this point for me to make that change.
So I need to work with what I have.
I have a table called Category. In that table, there are about 4 fields. One is idCategory which is the primary key. I also have two other fields: categoryname and categorycolor. I want a look up that presents the user with the category name and color concatenated in the dropdown (e.g., Food - Orange) but I want to store the value of categoryColor into the field I'm populating.
I've tried editing the mysql statement in the lookup manually. But I'm a bit confused about how that statement works within appgini. I tried the following statement and it presents the right information to the user in the dropdown. However, in the edit view, it does not automatically select the right selection from the dropdown based on what is in the database. It defaults to the first in the list. Also, in the grid view, the field information in color field (the one I'm trying to populate) is blank, even though there is data in the field.
The good news is that the update portion is working fine. When I edit a record, if I select the color using the current dropdown, it does in fact update the record with the correct color in that field. It's just that it's not working properly for the grid view and the edit view.
Here's the current sql statement in my lookup in appgini: SELECT `category`.`CategoryColor`, IF(CHAR_LENGTH(`category`.`CategoryName`) || CHAR_LENGTH(`category`.`CategoryColor`), CONCAT_WS('', `category`.`CategoryName`, ' - ', `category`.`CategoryColor`), '') FROM `category` ORDER BY 2
Any help would be most appreciated! Athelene
p.s. I realize it's always better to use primary keys for this. However, the database was created by someone else and it's too late at this point for me to make that change.
