This topic is locked
[SOLVED]

 Before add save data

11/19/2020 4:24:47 AM
PHPRunner General questions
A
alfonso authorDevClub member

I have 3 tables:
PEOPLE

---------------

  1. NAME
  2. CITY_ID
    CITIES

    ----------------

    1.ID
  3. NAME_CITY
    COPY_OF_PEOPLE

    ---------------
  4. NAME
  5. CITY_ID
  6. CITY_NAME
    When I add in PEOPLE I save values in other data with

    $data = array();

    $data["name"] = $values["name"];

    $data["city_id"] = $values["city_id"];

    DB::Insert("copy_of_people", $data );
    All ok. The same code I use to send an email
    The problem is how can I save also the name of the city. And send by mail. I try:
    $data["city_name"] = $values["????"];
    In ???? I don't know how can I get and save name_city from CITIES table
    Any idea? thanks

D
david22585 11/19/2020



I have 3 tables:
PEOPLE

---------------

  1. NAME
  2. CITY_ID
    CITIES

    ----------------

    1.ID
  3. NAME_CITY
    COPY_OF_PEOPLE

    ---------------
  4. NAME
  5. CITY_ID
  6. CITY_NAME
    When I add in PEOPLE I save values in other data with

    $data = array();

    $data["name"] = $values["name"];

    $data["city_id"] = $values["city_id"];

    DB::Insert("copy_of_people", $data );
    All ok. The same code I use to send an email
    The problem is how can I save also the name of the city. And send by mail. I try:
    $data["city_name"] = $values["????"];
    In ???? I don't know how can I get and save name_city from CITIES table
    Any idea? thanks


I would use a quick session. Before the e-mail and DB::Insert code, use this:



$rs = DB::Query("SELECT name_city FROM cities WHERE id = '".$values['city_id']."'");

while( $data = $rs->fetchAssoc() ){

$_SESSION["cityname"] = $data["name_city"];

}


Then you can use

$_SESSION["cityname"]

for

$values["city_name"] = $_SESSION["cityname"];

, and

".$_SESSION["cityname"]."

in the email.
At the end, just

unset($_SESSION["cityname"])

to clear that data.

Sergey Kornilov admin 11/19/2020

Use DBLookup function:

https://xlinesoft.com/phprunner/docs/dblookup_2.htm

$data["city_name"] = DB:DBLookup("SELECT name_city FROM cities WHERE id = ".$values['city_id']);
A
alfonso authorDevClub member 11/20/2020

Thanks. I try this code, but I get this error: Parse error: syntax error, unexpected ':' in /var/www/vhosts/.........
May be DB::DBLookup?
I have in Before Add

function BeforeAdd(&$values, &$message, $inline, &$pageObject)

{
$data = array();

$data["nif"] = $values["nif"];

$data["city_name"] = DB::DBLookup("SELECT name_city FROM cities WHERE id = ".$values['city_id']);

DB::Insert("empresas_copy", $data );


But then I got error:
Fatal error: Uncaught Error: Call to undefined method DB::DBLookup() in /var/www/vhosts/xxxxxxxx/xxxxxxxx/include/formulario_empresas_events.php:216 Stack trace: #0 /var/www/vhosts/xxxxxxxxx/classes/addpage.php(573): eventclass_formulario_empresas->BeforeAdd(Array, '', false, Object(AddPage)) #1 /var/www/vhosts/xxxxxxx/classes/addpage.php(394): AddPage->callBeforeAddEvent() #2 /var/www/vhosts/xxxxxxxx/classes/addpage.php(326): AddPage->processDataInput() #3 /var/www/vhosts/xxxxxxx/formulario_empresas_add.php(86): AddPage->process() #4 {main} thrown in /var/www/vhosts/xxxxxxxx/include/formulario_empresas_events.php on line 216

Sergey Kornilov admin 11/20/2020

You can use the following:

$data["city_name"] = DBLookup("SELECT name_city FROM cities WHERE id = ".$values['city_id']);
A
alfonso authorDevClub member 11/21/2020

Perfect!