Markie
Posts: 251
|
| Posted: 11/06/2008, 11:08 AM |
|
I have a members table with an extra field: mem_code
In my grid I have a hidden field (also named mem_code) in which I want to have the value of mem_code from the members table. This grid itself is connected to another database table (not members).
I have tried to use this before insert code:
global $DBConnection1;
global $members;
$db=new clsDBConnection1();
$uploaded1->mem_code->SetValue(CCDLookup("mem_code", "members","mem_id=". CCGetUserID(), $DBConnection1));
but it doesn't work. No errors, but my database field stays empty.
any advice ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 11/06/2008, 11:35 AM |
|
Hey Mark
Have you tried the DLookup action for the before show event?
The code you posted will not work at all.
I can show you what you need to do if you want to do it that way but Dlookup is much easier.
If you want to do it that way try:
$uploaded1->mem_code->SetValue(CCDLookup("mem_code", "members","mem_id=". $db->ToSQL(CCGetUserID(),ccsInteger), $db));
Where ccsInteger can be ccsText if your mem_id field is not integer
Let me know.
BTW. I always try to stay away from as much custom code as possible. You can use the Dlookup in the before insert event as well. Using Dlookup keeps it standard CCS and keeps the code portable
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Markie
Posts: 251
|
| Posted: 11/06/2008, 12:30 PM |
|
Hi John, I have tried the Before show -> DLookup action, but it seems I can only chose fields within the same table as the grid, not from the other (members) table. What do I have to do ?
If I use
$uploaded1->mem_code->SetValue(CCDLookup("mem_code", "members","mem_id=". $db->ToSQL(CCGetUserID(),ccsInteger), $db));
I get:
Fatal error: Call to a member function ToSQL() on a non-object ...
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Markie
Posts: 251
|
| Posted: 11/06/2008, 1:24 PM |
|
With some help from the CCS helpfile, I now have this code:
function uploaded1_BeforeShow(& $sender) {
global $uploaded1;
global $DBConnection1;
$uploaded1->mem_code->SetValue(CCDLookUp("mem_code","members","mem_id=". $DBConnection1->ToSQL(CCGetUserID(), ccsInteger), $DBConnection1) );
}
My database field is INT, however I don't get any result in the database.
What should I do to get mem_code in the database field ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 11/06/2008, 1:42 PM |
|
For me your code should looks like
function uploaded1_BeforeShow(& $sender) {
global $uploaded1;
$db = new clsDBConnection1();
$uploaded1->mem_code->SetValue(CCDLookUp("mem_code","members","mem_id=". $db->ToSQL(CCGetUserID(), ccsInteger), $db) );
}
just check exact name for your clsDBConnection1()...
_________________
Gena |
 |
 |
jjrjr1
Posts: 942
|
| Posted: 11/06/2008, 3:46 PM |
|
Exactly Gena.
Markie you need to be sure that clsDBConnection1 is actually the name of your database object created by common.php and extended in the main code page script of your page.
It usually named clsDB'the_name_of_your_connection_in_setup'
to find out what that is..., from the menu bar go to project.. settings .. connections
You will see connection names. If there is only one then it is easy. If not you will need to know what connection the table you are interested in is contained in.
For example let's say the conncetion name you see there is called mydatabase, your new database instance needs to be
$db = new clsDBmydatabase not $db= new clsDBConnection1
However, Dlookup will look up from any table regardless of what table your grid is using.
Take a look at all the properties for the Dlookup action.
The Domain property is where you put the name of the table. You can put any table name in your database there. In this case it would be members
Expression is the field you want to extract. In this case it would be mem_code
Criteria is the where clause of your lookup. (This can be tricky you need to concatinate some strings) In this case it would be "mem_id=".CCGetUserID()
Connection Would be the name of your projects database connection. You can click the 3 dots and a drop down list will appear. Pick the one that works.
Convert Result To Select the data type that is in your target control mem_code
Type of Target set to Control
Target set to the name of the control you want to load this value into. In this case mem_code
You should be able to cut and paste these values directly into your Dlookup action.
Let me know.
Take Care
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
Markie
Posts: 251
|
| Posted: 11/07/2008, 12:31 AM |
|
John, you're genious !
Your walkthrough for the dlookup action works perfect.
Gena, you know you're one of my favourites too
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 11/07/2008, 12:42 AM |
|
_________________
Gena |
 |
 |
|