This topic is locked

matching fields information

5/2/2008 9:58:21 PM
PHPRunner General questions
M
mrjtdude author

table:userpass

Field1: ID (primary key, auto increm.)

Field2:user

Field3:pass

Field4:Company Name - [Standard Oil]
How would I automatically get mysql to insert [Standard Oil] from the table and field above into the table and field below whenever I make a NEW record?
table:Company

Field1:userid (primary key, auto increm.)

Field2: companyid (NO primary key, NO auto increm.)

Field3:Company Name - [ ]
Thanks,

mrjtdude

J
Jane 5/5/2008

Hi,
use Add page: Before process event on the Events tab for this purpose.

Here is a sample:

global $conn;

$_SESSION["CompanyName"] = "";

$str = "select ID from userpass whee user='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

{

$str2 = "select CompanyName from Company where userid=".$data["ID"];

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_array($rs2);

$_SESSION["CompanyName"] = $data2["CompanyName"];

}



Then use $_SESSION["CompanyName"] as default value on the "Edit as" settings dialog on the Visual Editor tab.
Please note field names are case sensitive here.