Gary Finlay
|
| Posted: 01/19/2005, 3:46 PM |
|
Hi,
I'm using PHP/MySQL and CCS 2.3.2.
I have two tables (table1 and table 2). I have a record form to update table
1. On that form I want to prime some fields (when inserting) with the values
from a specific record (id=1) from table 2. I want these values to be
visible on the form when a user chooses to "Add new"
Can anyone help by telling me how do I do it please?
TIA
Gary Finlay
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 01/19/2005, 4:03 PM |
|
Something like this should work in the Before Show event to display the new values (from 2nd table) on the record form:
global $form_name;
// Open new connection
$conn = new clsDBpps_sys();
//Retrieve fields from the 2nd table
$SQL = "SELECT * FROM 2nd_table";
$conn->query($SQL);
$Result = $conn->next_record();
if ($Result)
{
// Populate record form fields with the data retrieved from the 2nd table
$form_name->control_name1->SetValue($conn->f("db_field_name1"));
$form_name->control_name2->SetValue($conn->f("db_field_name2"));
}
$conn->close();
You could use similar code in Before Insert event depending on how that should work.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
Gary Finlay
|
| Posted: 01/19/2005, 4:37 PM |
|
Peterr thanks for your help. What should I substitute for "clsDBpps_sys();" in the line of code below. When I substitute my connection name I get errors.
$conn = new clsDBpps_sys();
|
|
|
 |
Gary Finlay
|
| Posted: 01/19/2005, 4:50 PM |
|
I replaced...
$conn = new clsDBpps_sys();
with...
$conn = new clsDBMyConnectionName();
But now I'm getting the following error.....
Fatal error: Call to a member function on a non-object in /var/www/html/boreen/Bookings_events.php on line 35
Line 35 is...
$Bookings->BandB1Cost->SetValue($conn->f("overniteprecost"));
which relates to...
$form_name->control_name1->SetValue($conn->f("db_field_name1"));
Any ideas?
TIA
Gary Finlay
|
|
|
 |
peterr
Posts: 5971
|
| Posted: 01/19/2005, 5:42 PM |
|
I'm not sure what it is. Have you used "global $Bookings" at the beginning of that code?
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
 |
 |
Gary Finlay
|
| Posted: 01/20/2005, 11:39 AM |
|
Peterr, I sorted it. I mistyped a control's name (wrong case).
Thanks for your help.
Regards
Gary
|
|
|
 |