Gena
Posts: 591
|
| Posted: 02/20/2008, 3:11 AM |
|
i have 2 table in my database, one is with Main info, and another - with Extra info. It related as One-to-One. So I need to create a Record form with info from both table. How i cam do it? Is there any example?
_________________
Gena |
 |
 |
wkempees
|
| Posted: 02/20/2008, 3:52 AM |
|
A Record Form so you want to update both tables as well?
Displaying data from two 1on1 tables is as easy as joining them in the VQB.
Am sure you know how.
Select a.fields, b.fields from table1 as a, table2 as b
where 1.id = b.id
Update 2 tables at one (specially Insert) through Custom
Insert/Update/Delete
or using te MultiPage Record Form example.
Walter
"Gena" <Gena@forum.codecharge> schreef in bericht
news:547bc0ae899bd3@news.codecharge.com...
>i have 2 table in my database, one is with Main info, and another - with
>Extra
> info. It related as One-to-One. So I need to create a Record form with
> info
> from both table. How i cam do it? Is there any example?
> _________________
> Gena
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Gena
Posts: 591
|
| Posted: 02/20/2008, 4:04 AM |
|
Quote wkempees:
A Record Form so you want to update both tables as well?
Displaying data from two 1on1 tables is as easy as joining them in the VQB.
Am sure you know how.
Select a.fields, b.fields from table1 as a, table2 as b
where 1.id = b.id
Update 2 tables at one (specially Insert) through Custom
Insert/Update/Delete
or using te MultiPage Record Form example.
Thank you, Walter.
Sure, no problem to show record with info from two tables. But is it possible to update two tables at once? In the custom Insert/Update/Delete properties I see only one table to action, but what's about the second one?
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 02/20/2008, 4:06 AM |
|
just an idea. never tried it.
using MSSQL, if I create a View that consists of info of two table and then can I use this view in the Record??? Will it be Inserted/Updated/Deleted ???
_________________
Gena |
 |
 |
DonB
|
| Posted: 02/20/2008, 8:32 AM |
|
The view will not be updatable either. Although a 1-1 relationship does not
require 2 tables, there's probably some underlying reason it was done that
way. From a design standpoint, I'd really suggest the two tables be made
into one physical table that you can then update/insert easily and create
two views to represent the two logical tables you apparently need. Derive
them from the combined physical table by choosing the subset of columns for
each when you define the view.
--
DonB
"Gena" <Gena@forum.codecharge> wrote in message
news:547bc17c160246@news.codecharge.com...
> just an idea. never tried it.
>
> using MSSQL, if I create a View that consists of info of two table and
> then
> can I use this view in the Record??? Will it be Inserted/Updated/Deleted
> ???
> _________________
> Gena
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
Gena
Posts: 591
|
| Posted: 02/20/2008, 9:55 AM |
|
thanks, DonB
But the problem is that i need to use 2 tables and can't use just one common. The reason is that I have more tables that related like 1to1 to my tabel, so
Table1 <-> TableR
Table2 <-> TableR
Table3 <-> TableR
as you can see I need "two" different tables to relate each other.
_________________
Gena |
 |
 |
wkempees
|
| Posted: 02/21/2008, 5:10 AM |
|
Views are Views....
Your Record form have it work on either a View or a joined 2 tables.
In the Custom Insert/Update/Delete handle the main table.
In the AfterInsert/Update/Delete handle the other table.
??
Walter
"Gena" <Gena@forum.codecharge> schreef in bericht
news:547bc69837fe51@news.codecharge.com...
> thanks, DonB
>
> But the problem is that i need to use 2 tables and can't use just one
> common.
> The reason is that I have more tables that related like 1to1 to my
> tabel, so
>
>
> Table1 <-> TableR
> Table2 <-> TableR
> Table3 <-> TableR
>
> as you can see I need "two" different tables to relate each other.
> _________________
> Gena
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Gena
Posts: 591
|
| Posted: 02/21/2008, 5:20 AM |
|
Quote wkempees:
Views are Views....
Your Record form have it work on either a View or a joined 2 tables.
In the Custom Insert/Update/Delete handle the main table.
In the AfterInsert/Update/Delete handle the other table.
??
No. 
thank you, Walter
_________________
Gena |
 |
 |
wkempees
|
| Posted: 02/21/2008, 5:44 AM |
|
Thanks for the smiley but what about the "No"?
Need anything more?
Walter
"Gena" <Gena@forum.codecharge> schreef in bericht
news:547bd7ab62f260@news.codecharge.com...
> Quote wkempees:
> Views are Views....
> Your Record form have it work on either a View or a joined 2 tables.
> In the Custom Insert/Update/Delete handle the main table.
> In the AfterInsert/Update/Delete handle the other table.
>
> ??
> No. 
>
> thank you, Walter
>
> _________________
> Gena
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.yessoftware.com/
>
|
|
|
 |
Gena
Posts: 591
|
| Posted: 02/21/2008, 9:39 AM |
|
Quote wkempees:
Thanks for the smiley but what about the "No"?
Need anything more?
You have put two question marks (??) so you ask me like "do you have a questions?" and I said "No", so it means NO questions
_________________
Gena |
 |
 |
wkempees
|
| Posted: 02/21/2008, 11:31 AM |
|
Ok well done!
Till next we meet.
Walter
"Gena" <Gena@forum.codecharge> schreef in bericht
news:547bdb7510cf84@news.codecharge.com...
> Quote wkempees:
> Thanks for the smiley but what about the "No"?
> Need anything more?
>
>
> You have put two question marks (??) so you ask me like "do you a
> questions?"
> and I said "No|, so it means NO questions 
> _________________
> Gena
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Gena
Posts: 591
|
| Posted: 02/26/2008, 5:21 AM |
|
I'm finally tried it and went into problem...
So I have MainTable and RelatedTable.
I have Record form with the fields from MainTable and I need to put also some fields from RelatedTable. I need to be able Insert/Update and Delete records from my db.
Is anybody can provide me a working example please? ccs+php+mysql is good.
tia
_________________
Gena |
 |
 |
wkempees
Posts: 1679
|
| Posted: 02/26/2008, 8:13 AM |
|
So, you're back then 
What is your exact problem, which of the following 2 is completed:
1: the RecordForm is displaying and the data from both related tables is correctly displayed.
2: The RecordForm accepts updates to fields from Both table 1 and 2, but Insert/Update/Delete does not work
Xtra:
Delete, using CustomDelete, identifying primary key item on table 1 will correctly delete the record.
So in AfterExecuteDelete, Row from Table1 is deleted, you need to pickup the primary key value for table2 and execute ans sql statement like:
$sql = 'Delete from Table2 where keyfield=' . $saved_value;
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
Gena
Posts: 591
|
| Posted: 02/26/2008, 9:47 AM |
|
Quote wkempees:
So, you're back then
What is your exact problem, which of the following 2 is completed:
1: the RecordForm is displaying and the data from both related tables is correctly displayed.
2: The RecordForm accepts updates to fields from Both table 1 and 2, but Insert/Update/Delete does not work
Xtra:
Delete, using CustomDelete, identifying primary key item on table 1 will correctly delete the record.
So in AfterExecuteDelete, Row from Table1 is deleted, you need to pickup the primary key value for table2 and execute ans sql statement like:
$sql = 'Delete from Table2 where keyfield=' . $saved_value;
Ciao, Walter!
yes, it's me again. :)
it seems that I have (1) working good. but (2) - no. I am really confused about code and how do i Insert/Update/Delete MainTable and RelatedTable??? It seems easy but can't figured it out - how and where? Is there any working example?
I was used Custom Insert/Update/Delete for one table, but not with two tables...
_________________
Gena |
 |
 |
wkempees
Posts: 1679
|
| Posted: 02/26/2008, 1:03 PM |
|
Ok
Custom I/U/D is for one table, use that for the maintable.
Then you want the AfterInsert/Update/Delete to do the second table.
In the AfterInsert you probably need the autoincremented primarykey value of Table1 to prime Table2.
For the Update/Delete you need to know the primary key too, but you probably have that on the URl already or somewhere else in the Form.
What remains is the code for the field by field transfer for the Insert and the Update.
All three the After...Events need a common piece of coding:
$db = new clsDB<name of your connection>;
$db->open();
$sql='.........';
&db->query($sql);
$db->close();
to be continued.....
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 02/26/2008, 1:29 PM |
|
For the Delete:
$sql = 'DELETE from <table2name> WHERE <primarykeyfieldtable2name> =' . CCGetFromGet('id','');
assuming the URL is something like ?id=12345
otherwise adjust the fieldname or use a CCGetFromPost('fieldname')
where 'fieldname'is the identifying field.
For the Update:
$sql = 'UPDATE <table2name> '
. ' SET 'fieldname1 ='. $db->ToSQL( $Component->fieldname1->GetValue() , TYPE ) '
. ', fieldname2=' . $db->ToSQL( $Component->fieldname2->GetValue() , TYPE ) '
. ' WHERE <primarykeyfieldname> =' . CCGetFromGet('id','');
The TYPE needs to be replaced with the appropriate ccsDate, ccsBoolean, ccsInteger, ccsFloat, ccsText, ccsMemo depending on the data fields type (read Helpfile: ToSQL) CCS will do proper convert for you depending on various settings you set in Connections.
So what remains is the INSERT
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 02/26/2008, 2:24 PM |
|
For the Insert:
$sql = 'INSERT INTO <table2name> '
. ' ( fieldname1, fieldname2, ......) VALUES ( '
. 'fieldname1 ='. $db->ToSQL( $Component->fieldname1->GetValue() , TYPE ) '
. ', fieldname2=' . $db->ToSQL( $Component->fieldname2->GetValue() , TYPE ) '
. ' );
Just make sure you have the primarykey value correctly.
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
Gena
Posts: 591
|
| Posted: 02/26/2008, 2:33 PM |
|
Great! Walter!
And just to finish - could you specify exctly the Events where I need to put all this code please?
after that may be you can create a small ccs project, sumarize a text (description) and put it in the Tips forum here
or even create a Tutorial using wink
_________________
Gena |
 |
 |
Gena
Posts: 591
|
| Posted: 02/26/2008, 2:37 PM |
|
and as a wish this should be all done just automatically within CCS as a standard feature...
_________________
Gena |
 |
 |
wkempees
|
| Posted: 02/26/2008, 4:57 PM |
|
first, am not guaranteeing it works straight out of this post, I do make
typo's too.
Second, it is 2 hours pas midnight here.......yawn.
as for the rest......
The RecordForm you are working on, properties has the Custom I/U/D
The RecordForm also has event_tab in the properties, there you will find the
AfterExecuteInsert, AfterExecuteUpdate and AfterExecuteDelete.
Reread the post and into each copy the code that all share.
Then ...... oh well.
You might want to reread some post we shared regarding obtaining the
last_insert_id (search)
It will point you out the missing part for the Insert as well as show you
how to handle the event.
About the CCS should cover this, you made me think today it would be handy
to
right click the AfterExecuteInsert event and add a
CustomInsert/Update/Delete there
presenting us with the same interface as the normal one.
CCT? Yes?
Walter
|
|
|
 |
Gena
Posts: 591
|
| Posted: 02/26/2008, 5:29 PM |
|
Walter, yes, I know that about 2.30 pass midnight here too 
Thanks for your explanation. i was thinking like this. Today morning I will give it a try.
and about mine and your idea about CustomInsert/Update/Delete for event - yes, this could be much more easy to manage this all... YES?
_________________
Gena |
 |
 |
|