CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How do I do this in CCS?

Print topic Send  topic

Author Message
saseow

Posts: 744
Posted: 09/27/2008, 9:28 PM

This is a simple thing to program but I have no idea where to put this in CCS. Please help if you can:

I have two tables, one is base data (table1) and the other is the base data that is modifiable by the user (table2). Table2 has a user_id field naturally with the default value of CCGetUserID().

So, When a user logs in and chooses to go to table2, I want to check whether his user_id exists in table2 or not. If it does not exist i.e. he is a brand new user, I want to copy all of the base data in table1 over to table2 with the new users ID in the user_id field then open the grid for him to modify.

Easy isn't it! Not if you don't know where/how to add this in CCS.

Any help will be so appreciated!!!
View profile  Send private message
Waspman

Posts: 948
Posted: 09/28/2008, 4:28 AM

You’ll need some way of recording whether the user has created a record in table 2.

So in the user table have yes/no field etc.

All new users have a default set to “No” when they sign up.

Have 2 panels on your page one showing if they have created the record in table 2 and one showing if they haven’t

One contains a record update form the other shows a record insert form.

Populate the later from a copy of table 1 on the page with all the fields hidden, so the user can’t see it.

You could just create a copy of the base elements in table 2 at the time the user record is created.


HTH


T

_________________
http://www.waspmedia.co.uk
View profile  Send private message
saseow

Posts: 744
Posted: 09/28/2008, 6:15 AM

Thank you for the repy HTH, Thinking about this overnight I am going to try something like this:

When a new user logs in, check table2 to see if his/her user_id exists. (I am sure MySQL will have something to do this. Rather like ADODB recordcount.) If it does not exist, I will update table1 (in which I will put a user_id) with the user's id and then copy table1 to table2. The user_id in table1 will serve no other purpose.

I think this is the simplest way to go about it. Still have to figure the coding in CCS out however. :)

Thanks again,

Trevor
View profile  Send private message
GabrielAkoh

Posts: 9
Posted: 09/28/2008, 8:35 PM

Hi saseow,

If what you want is to have new users complete their registration at first log in, make it clearer. In which case, you do not need a second table.


View profile  Send private message
datadoit
Posted: 09/29/2008, 7:26 AM

Before you commit yourself to this, may want to think of what headaches
this may bring down the road as you must constantly maintain two or more
tables of similar information, thus in effect doubling your workload.
Is this for logging changes made to the data by users? Perhaps we could
make design recommendations that would save time and effort, and of
course, how to do that in CCS, or even directly in your database of
choice (triggers).

saseow

Posts: 744
Posted: 09/29/2008, 7:37 AM

The new user is always presented with the same base data which they can modify hence the users table which will contain all the base data and a user ID. I do not want a single table containing the base data as well as the users modified base data.

I know nothing about triggers in Mysql or how to call them from CCS.

Thank you for the reply,

Regards,

Trevor
View profile  Send private message
datadoit
Posted: 09/29/2008, 7:53 AM

Okay, real simple.... In the form's Before Show event, check for the
existence of the record:

http://docs.codecharge.com/studio40/html/ProgrammingTec...neFormMode.html

If you're not in 'Edit Mode', then do a lookup to your user's table to
get the default values for your record form fields, similar to:

if (!$Container->EditMode) {

global $YourConnection;
$db = new clsDBYourConnection();
$sql = "SELECT * FROM users WHERE whatever";
$db->query($sql);
$Result = $db->next_record();
if ($Result) {
$Container->Field1->SetValue($db->f("users_field1"));
$Container->Field2->SetValue($db->f("users_field2"));
etc.
}
$db->close();

}
saseow

Posts: 744
Posted: 09/29/2008, 8:23 AM

Hi Datadoit,

This looks so promising! One problem is that the test of edit mode always comes up as the Add Mode. Any ideas about this?

Would it not be easier to check if the user ID exists in the table and if not, do your code above?
In that case, do you know if PHP has a function to test if a certain record is in a table?

Thanks so much,
Trevor
View profile  Send private message
saseow

Posts: 744
Posted: 09/29/2008, 8:28 AM

Hold it Dadadoit! It is working. Let me try the rest of it and I will come back to you. Yah!!
View profile  Send private message
saseow

Posts: 744
Posted: 09/29/2008, 9:34 AM

Hi Dadadoit,

This is what I have got: ( The first 2 fields are ID (autoincrement field) and user_id which I don't want to include)

//Custom Code @206-2A29BDB7
// -----------------------

if (!$Container->EditMode) {
//Records exist for this user
// Else
//New user say add the base records from the poolgeek stats.
global $hockey_stats;
$db = new clsDBhockey_stats();
$sql = "SELECT * FROM statistics_poolgeek";
$db->query($sql);
$Result = $db->next_record();
if ($Result) {
$Container->Field3->SetValue($db->f("position_id"));
$Container->Field4->SetValue($db->f("team_id"));
$Container->Field5->SetValue($db->f("gp"));
$Container->Field6->SetValue($db->f("g"));
$Container->Field7->SetValue($db->f("a"));
$Container->Field8->SetValue($db->f("p"));
$Container->Field9->SetValue($db->f("+/-"));
$Container->Field10->SetValue($db->f("pim"));
$Container->Field11->SetValue($db->f("ppg"));
$Container->Field12->SetValue($db->f("ppa"));
$Container->Field13->setValue($db->f("ppp"));
$Container->Field14->SetValue($db->f("shg"));
$Container->Field15->SetValue($db->f("sha"));
$Container->Field16->SetValue($db->f("shp"));
$Container->Field17->SetValue($db->f("sog"));
$Container->Field18->SetValue($db->f("shot%"));
$Container->Field19->SetValue($db->f("gwg"));
$Container->Field20->SetValue($db->f("fw"));
$Container->Field21->SetValue($db->f("f%"));
$Container->Field22->SetValue($db->f("hits"));
//$Container->Field23->SetValue($db->f("atoi"));
}
$db->close();
}
// -------------------------
//End Custom Code

I keep getting the following arror;
Notice: Undefined property: clsEditableGridstatistics::$Field3 in C:\php webs\hockey_stats\statistics_pg_mod_events.php on line 32

Fatal error: Call to a member function SetValue() on a non-object in C:\php webs\hockey_stats\statistics_pg_mod_events.php on line 32

Any idea what my problem is?
View profile  Send private message
saseow

Posts: 744
Posted: 09/29/2008, 10:52 AM

Sorry Dadadoit, got that working but it is not adding the rows to the DB.

I will play with it some more and let you know.
View profile  Send private message
datadoit
Posted: 09/29/2008, 12:01 PM

Note that this routine is just setting 'default' values for your record
form if the record doesn't already exist. After that, the record must
be saved for the information to be recorded.

If you want information written to the database without any human
interaction, then that's a different routine entirely from the sample given.
saseow

Posts: 744
Posted: 09/29/2008, 12:12 PM

Hi datadoit,

The form is actually an editable grid and yes, I do want it written to the database and then displayed. There are aprox 440 records to insert into the table in about 21 fields.

If you can point me in the right direction I would appreciate it so much!

I am also having a huge hassle with the EditMode in the editable grid when I try to ascertain if any records are returned or not i.e. checking if the user has alreday had the records transferred to the table. I use the following code and it returns the 'Add Mode" wether records are reurned or not. This is driving me nuts!

In the BeforeShow event:

if ($Container->EditMode) {
//Edit Mode
echo "Edit mode";
} else {
//Add Mode
echo "Add mode";
}

Thanks so much,

Trevor
View profile  Send private message
datadoit
Posted: 09/29/2008, 12:22 PM

EditMode only works for record forms, not editable grids (I think).
Otherwise, do a lookup to see if the record is there:

global $YourConnection;
$db = new clsDBYourConnection();
$Exists = CCDLookUp("user_id", "your_table", "user_id=" .
$db->ToSQL(CCGetUserID(), ccsInteger), $db);
$db->close();
if ($Exists) {

}

I'll check back in later with more on the other stuff....
Waspman

Posts: 948
Posted: 09/29/2008, 1:01 PM

I've just done a similar thing with 180 field record located in a base table that has to be transferred to another table as a new record and identified as belonging to a specific user.

Like I said above I set a control field value when the user first sets up the account (or enrols) in this case is a training course booking system. It requires in another table to be populated with all the base data(personal info etc) from the user/trainee profile. When the user goes to a particuilar page there are 2 panels as above. Slightly different cos it asks the user to iniate the setup of the second table (it's not always needed), but it could happen in the before show event. It goes to a page and does it with some simple custom sql. I have a little confirmation text, actually its an idea DD gave me last year.

It's very easy, it must be if I can do it;-)

T
_________________
http://www.waspmedia.co.uk
View profile  Send private message
saseow

Posts: 744
Posted: 09/29/2008, 3:59 PM

Hi Waspman,

Thank you for this reply. I will give this a try and post the results tomorrow. At the very least, it has given me some food for thought. In my case the base data is not one record though but is 440 records in 21 fields. A record insert form is not going to handle that.

Thanks again,

Trevor
View profile  Send private message
Waspman

Posts: 948
Posted: 09/30/2008, 1:28 AM

I use a custom script to insert.

Get the data however you want to based on the control field state either assign to variables or a table and use the custom script to insert into new record. Just a bit long winded that's all.

T
_________________
http://www.waspmedia.co.uk
View profile  Send private message
saseow

Posts: 744
Posted: 09/30/2008, 4:54 AM

Thank you all for your input. In the end I simply went traditional and used SQL for everything.
This is my solution:

//Check if user_id exists in the table or not.
if(mysql_num_rows(mysql_query("SELECT user_id FROM table2 WHERE user_id = ".CCGetUserID()))){
// user_id is already there
}
else
//user_id not in table so add base data
{
global $hockey_stats;
$db = new clsDBhockey_stats();
$sql = "INSERT INTO table2 ( list of fields )
SELECT (list of fields)
FROM table1;";
$db->query($sql);
//Set the user_id
$sql = "UPDATE table2 SET table2 = " .CCGetUserID()." where user_id IS NULL";
$db->query($sql);
$db->close();
}

Works like a dream!

Omce again, thank you all so much. This is a fantastic forum.

Trevor
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.