I previously had a post where I said that when I was in the browse screen and clicked on a record, the edit screen did not come up. I copied the below from that post.
I have created 6 tables with their corresponding browse and edit forms. When I am in the browse form and click on a record, the edit form does not come up. On the other hand if I click on the 'Add record' button, the form does come up to add a record.
I did not see anything in the video tutorials that said I needed to do anything special to cause the edit form to come up when clicking on a record in the browse form.
Since then I have done a fresh install using verison 2.8.1 (build 554) and once again added tables forms, etc. Although my other problems have gone away, I still do not get an edit form when I click on a record in the browse screen. Do I have to do anything special to get this feature to work? I have not selected any other form in the 'form to edit' option.
You are right. The primary key was blank and in fact was missing. I dropped the table and added the ‘PRMARY KEY’ option to the CREATE TABLE statement. It now looks like the following:
Now I am running into some issues with reloading the data. My client sends me the data in a spreadsheet which I then convert to a CSV file. I was using 'CSV using LOAD DATA' under the 'Import' tab to load my data, Now that I have defined a Primary Key, this is no longer working. It would only load the first row and the primary key would be blank. In the CSV file, the first data line looks like this:
“","04-204","Jan","Management Company","303-555-6206 ","3206 Main St.","","Denver","CO","80129",""
I tried entering data through the Insert option in phpMyAdmin. Although it created the row, there was nothing in the Primary key field.
I then removed the form and its objects and recreated it. I clicked on add record. I was able to add the record and click on Save. When I went back to phpMyAdmin, the record I added does have a primary key so I know I am on the right track. When I click on the record in the browse screen, it does bring up the record in the Edit form.
It comes down to 2 questions. What is the best way to load my data into a table when there is a primary key? Secondly, can you please give a little explanation on how the primary key is generated?
I was hoping to show the browse/edit feature to my client tomorrow morning and it would be nice to have reloaded their data using the primary key.
Now I am confused. I was under the impression that the primary key was generated by NuBuilder. I already had unique values for the first column in each table, before I added the <table name>_id field and made it a primary key field. In my example, 'building_unit' has unique values. Can I make that the primary key? If yes, should I rename building _unit to agent _id?
After my last post, I did some more testing and ran into some new problems.
I created a new table called unit_agent with the following SQL statement:
CREATE TABLE IF NOT EXISTS `unit_agent` (
`unit_agent_id` varchar(10) NOT NULL,
`una_agent` varchar(25) DEFAULT NULL,
`una_company` varchar(40) DEFAULT NULL,
`una_phone` varchar(12) DEFAULT NULL,
`una_address_1` varchar(40) DEFAULT NULL,
`una_address_2` varchar(40) DEFAULT NULL,
`una_city` varchar(25) DEFAULT NULL,
`una_state` varchar(2) DEFAULT NULL,
`una_zip` varchar(5) DEFAULT NULL,
`una_email` varchar(40) DEFAULT NULL,
PRIMARY KEY (`unit_agent_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='agent assigned to unit';
As you can see the primary key is now unit_agent_id. I removed the first column in my CSV file (which had been blank) and reloaded the data. The new first colum had unique data and became my primary key. I had no problems with the load of the data.
I created a new form with browse and edit. Everything appeared to be working fine. When I clicked on a browse row, it popped up the edit screen. But when I tried the 'add record' and the 'clone' and went back to the browse screen, the only thing I saw was new rows with only a NuBuilder generated key despite entering a unique key for the 'add record' and the 'clone'.
Afte writing the last post I saw the following in another post called "What about foreign keys":
If you currently have PKs and FKs in any string format, nuBuilder will work with what you've got and just create uniqid() strings for new records.
Based on the above statement and my problems with 'add record' and 'clone', I am not sure how to handle the primary key issue. If I use my unique values for a primary key, that will only work with browse and edit. 'Add record' and 'clone' will create NuBuilder primary keys which defeats my using my own values for primary keys.
If I have NuBuilder handle the primary keys, how do I do a mass load of my data?
when you add a new record (or clone an existing one) nuBuilder create itself the PK for the record using uniqid() function (http://wiki.nubuilder.com/tiki-index.ph ... uilderDocs) so you don't have to manage it: you must only indicate the name of the field containing the PK in the Form General tab; in Reorder Form Objects tab you shouldn't have any PK object (no PK field visible on edit form).
To import data from a CVS file, you can run a little php script that read one by one records from CVS file, generate, for each record, a PK with uniquid() function and execute an INSERT query in your db.