[SOLVED] Form Detail Tempate | Update query | Get id of dropdown database join element + Solution

marcq

Member
Hi,

I have created a new detail form template.

I'm trying to update data with a query (php form plugin) with the value of a dropdown database join element.

upload_2016-5-24_13-53-24.png
I'm unable to get the id with

PHP:
$blocationcrew=$data['fab_booking___boarding_location_crew'];[PHP]

Neither with [PHP]$blocationcrew=$data['fab_booking___boarding_location_crew_raw'];[PHP]

Form Plugin PHP
[PHP]
$db = JFactory::getDbo();

// echo "<pre>";print_r($data);exit;

$bookingid=$data['fab_booking___id'];

$bcrewattending=$data['fab_booking___book_crewattending'];
$lcrewend=$data['fab_booking___book_crewend'];
$blocationcrew=$data['fab_booking___boarding_location_crew'];
$llocationcrew=$data['fab_booking___landing_location_crew'];

// var_dump($id);
// var_dump($bcrewattending);
// var_dump($lcrewend);

$query3 = $db->getQuery(true);
$query3 = "UPDATE fab_booking SET book_crewattending = '$bcrewattending' WHERE id = '$bookingid'";
$db->setQuery($query3);
$resultblocationcrew=$db->execute();

$query4 = $db->getQuery(true);
$query4 = "UPDATE fab_booking SET book_crewend = '$lcrewend' WHERE id = '$bookingid' ";
$db->setQuery($query4);
$resultllocationcrew=$db->execute();

$query5 = $db->getQuery(true);
$query5 = "UPDATE fab_booking LEFT JOIN fab_boarding_location_crew ON fab_booking.boarding_location_crew = fab_boarding_location_crew.id SET fab_booking.boarding_location_crew = '$blocationcrew' WHERE (fab_booking.id ='$bookingid'";
$db->setQuery($query5);
$boardinglocationcrew = $db->execute();


$query6 = $db->getQuery(true);
$query6 = "UPDATE fab_booking LEFT JOIN fab_landing_location_crew ON fab_booking.landing_location_crew = fab_landing_location_crew.id SET fab_booking.landing_location_crew = '$llocationcrew' WHERE fab_booking.id = '$bookingid'";
$db->setQuery($query6);
$landinglocationcrew = $db->execute();

I w upload_2016-5-24_13-53-24.png upload_2016-5-24_13-53-24.png ould appreciate your support.

Marc
 
Have you tried $this->data, rather than $data?

-- hugh
I tried but it doesn't work

The following error is displayed, which shows that the label ('embarquement 2' and 'Lieu d'embarquement 2') is retrieved instead of the id.

Code:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'embarquement 2' WHERE fab_booking.id ='35'' at line 1 SQL=UPDATE fab_booking LEFT JOIN fab_boarding_location_crew ON fab_booking.boarding_location_crew = fab_boarding_location_crew.id SET fab_booking.boarding_location_crew = ' Lieu d'embarquement 2' WHERE fab_booking.id ='35'
 
Last edited:
If you want the value rather than the label of an element, append _raw to the name you use in $this->data[].

-- hugh
 
Try var_dump()'ing it, it may be an array.

Code:
$blocationcrew = $data['fab_booking___boarding_location_crew'];
var_dump($blocationcrew);exit;

... if that shows you it's an array, replace the var_dump() line with ...

Code:
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

-- hugh
 
Try var_dump()'ing it, it may be an array.

Code:
$blocationcrew = $data['fab_booking___boarding_location_crew'];
var_dump($blocationcrew);exit;

... if that shows you it's an array, replace the var_dump() line with ...

Code:
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

-- hugh

Hi hugh,

thank you for your time and support

It's an array

http://www.screencast.com/t/X6kH4MEpL

but it doesn't work with

Code:
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

or

Code:
$llocationcrew = is_array($llocationcrew) ? llocationcrew[0] : $llocationcrew;

http://www.screencast.com/t/s1A9tnNv5

I've got only problem with arrays, other fields are displayed correctly.
 
both database join dropdowns

Erratum : I've tried both solutions :

Code:
$blocationcrew=$this->data['fab_booking___boarding_location_crew_raw'];

returns "array(1) { [0]=> string(1) "4" } "

which is the value I need to save.

Code:
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

returns "NULL"
 
I've checked the query which is working fine in phpMyAdmin SQL, value populate accordingly the database row :

Code:
UPDATE fab_booking LEFT JOIN fab_boarding_location_crew ON fab_booking.boarding_location_crew = fab_boarding_location_crew.id SET fab_booking.boarding_location_crew = '4' WHERE fab_booking.id ='35'

No clue why it isn't working
 
So just to be clear, your code is ...

Code:
$blocationcrew=$this->data['fab_booking___boarding_location_crew_raw'];
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

-- hugh
 
So just to be clear, your code is ...

Code:
$blocationcrew=$this->data['fab_booking___boarding_location_crew_raw'];
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

-- hugh

Hi Hugh

No my code is

Code:
$blocationcrew=$this->data['fab_booking___boarding_location_crew_raw'];

or

Code:
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

I'm not "using" both a the time. I wrote the first code and the second one is of yours.

According #14 my code is returnin a value, but the second one a null value.

Thanks in advance for your support.

Marc
 
Last edited:
OK, well what I posted is what you need.

Hi Hugh,
Sorry to bother you with that but

Code:
$blocationcrew = is_array($blocationcrew) ? $blocationcrew[0] : $blocationcrew;

doesn't work :

http://www.screencast.com/t/HLpobAwY

I would appreciate if you could have a look directly in my backend. You will find all needed informations in My Site : LA NEPTUNE, Notes (form, Elements ID, links, frontend user and pw).

Thank you in advance for your support.

Cheers, Marc
 
Last edited:
I just deleted and recreate the database join element thinking it would solve the problem.

But the problem remains.

result var_dump($blocationcrew) : array(1) { [0]=> string(1) "1" }

Code:
// Crew boarding location
$blocationcrew=$this->data['fab_booking___boarding_location_crew_raw'];
// var_dump($blocationcrew);exit;
$blocationcrew = is_array($blocationcrew) ? blocationcrew[0] : $blocationcrew;

Code:
// Update crew boarding location
$query = $db->getQuery(true);
$query = "UPDATE fab_booking LEFT JOIN fab_boarding_location_crew ON fab_booking.boarding_location_crew = fab_boarding_location_crew.id SET fab_booking.boarding_location_crew = '$blocationcrew' WHERE fab_booking.id ='$bookingid'";
$db->setQuery($query);
$boardinglocationcrew = $db->execute();

Would appreciate some help. Thanks in advance, cheers, Marc
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top