Php validation code

Status
Not open for further replies.

starbuck69400

New Member
Hello every body,

I try to use a php validation code on a display element to get a value from a field in function of the value i've select in my databasejoin element (cnx_cnx___Adliv):

Code:
$adliv== '{cnx_cnx___Adliv}';
$db =&JFactory::getDBO();
$db->setQuery("SELECT `Nom` FROM `cnx_client` where $adliv = '1029092'");
$fieldA = $db->loadResult();
return $fieldA;

Cou'ld you tell me what i'am wrong?

Thanks for help.
 
I had try this code but without more success:

Code:
$adliv = JRequest::getVar('cnx_cnx___Adliv');$db=$JFactory::getDBO();$db= ('SELECT nom FROM cnx_client where adliv= $adliv';return $db->loadResult();

Somebody can redirect me in the right direction?

Thank's for help
 
where $adliv = '1029092'
What do you want to achieve/compare?
The syntax is WHERE table-column=some-value.
Is adliv a column of cnx_client and you want to select one record with adliv= content of your cnx_cnx___Adliv element?

Code:
$adliv== '{cnx_cnx___Adliv}'; 
$db =&JFactory::getDBO();
$q="SELECT `Nom` FROM `cnx_client` where adliv = '$adliv'";
//var_dump($q);exit; //uncomment this line for debugging your query
$db->setQuery($q); 
$fieldA = $db->loadResult(); 
return $fieldA;
 
Is adliv a column of cnx_client and you want to select one record with adliv= content of your cnx_cnx___Adliv element?

Yes it's exactly that i want but with your code and by uncomment the debugging line i obtain this:

HTML:
string(47) "SELECT `Nom` FROM `cnx_client` where adliv = ''"

It seems that $adliv== '{cnx_cnx___Adliv}'; don't return any value.
I don't understand why.
 
php validation
I've overlooked this; in php validation you can't use placeholders. See the tooltip for how to access element data (try JRequest::getvar('cnx_cnx___Adliv'))
 
Ok thank's for your help.
It's a little bit clearly for me but With this code:

Code:
$adliv=JRequest::getvar('cnx_cnx___Adliv'); 
$db =&JFactory::getDBO();
$q="SELECT nom FROM cnx_client where adliv = '$adliv'";
var_dump($q);exit; //uncomment this line for debugging your query
$db->setQuery($q); 
$fieldA = $db->loadResult(); 
return $fieldA;

I obtain this error:

HTML:
string(51) "SELECT nom FROM cnx_client where adliv = 'Array'"

Thank's for help
 
Sorry for my insistance but i don't find any solution to my problem.

I believed at first that I had to use (' cnx_cnx ___ Adliv_raw ') to obtain the value and not an array but my variable $adliv seems to return an array and my sql select can't know which value to get.

To express my need here is a plan:

In a mysql table "cnx_cnx" i have

Adliv Name
1034121 Toto
1034122 Hubert

In my form i've (for the moment) two ?l?ments.
The first is a database join on cnx_cnx_adliv and i would like that the second is a display ?l?ment which show the name value of table cnx_cnx in fonction of the raw data in the databasejoin ?l?ment.

So in fact:
if in databasejoin ?l?ment i've 1034121 i expect to have in my display ?l?ment TOTO.

Is there a way to obtain this result?

Thank's again for you help.
 
For the code:
you can also use
var_dump($adliv);
to see what it is (so maybe $adliv[0] will contain what you need).

But I'm not sure what you are trying to do, it doesn't sound like a validation.

In a dbjoin element you can select the value (Adliv), this is what is stored in the database.
And you can select the label (Name) for what is displayed in the form/list.

If you want to fill a second element depending on the selection of the first one you can use the cascading dropdown element.
Maybe you'll have to update from GitHub to get it
http://fabrikar.com/forums/index.ph...s/#Installing_and_Enabling_Additional_Plugins
 
Thank's troester
You're right! With cascading dropdown it work's. Not exactly how i would but it work.
Sometime the answer is front of us.

many thank's again.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top