User Information in Php List Plugin

tiagovareta

Member
Hi,

I use the following code in an element, to load the element with the user's assessor number:

// Get a db connection.
$myDb = JFactory::getDbo();

// Create a new query object.
$myQuery = $myDb->getQuery(true);

$myQuery
->select('numero_assessor_ctg')
->from('tb_contactos_geral')
->where('id_login_ctg = ' . $myDb->quote('{$my->id}'));

// Assign the query to the db
$myDb->setQuery($myQuery);

// Load the results as an array of objects.
$id=$myDb->loadResult();

return $id;

I tried to use this code in the PHP Plugin from a list and it does not work. However if you put only the "{$ my-> id}" in a variable, it will fetch the id of the user. So I can access the id of the user to make the query.

I use querys like this to write data to bd (in the list plugin):

$query1 = "INSERT INTO tb_email (email_eml, id_contacto_geral_eml) VALUES ('$email', '$id')";
$db->setQuery($query1);
$db->execute();

I'll have to use a query of this sort to get the assessor number, how do I do the element, right?
It would be something like this:

$query = "SELECT numero_assessor_ctg FROM tb_contactos_geral WHERE id_login_ctg = {$my->id}";

My question is:
- How do I put the query result in a variable, then call it?
 
Hi,

I think I have partially solved my situation!
Since I want to know 3 fields of the logged in user (group, district, region), I did 3 query's:

$querygrupo = "SELECT grupo FROM tb_contactos_geral WHERE id_login_ctg = '$id_user'";
$db->setQuery($querygrupo);
$grupo = $db->loadResult();

$querydistrito = "SELECT distrito FROM tb_contactos_geral WHERE id_login_ctg = '$id_user'";
$db->setQuery($querydistrito);
$distrito = $db->loadResult();

$queryregiao = "SELECT regiao FROM tb_contactos_geral WHERE id_login_ctg = '$id_user'";
$db->setQuery($queryregiao);
$regiao = $db->loadResult();

Before the query's I have:
$db = FabrikWorker::getDbo(); //Liga??o ? BD APP OriGest
$id_user = '{$my->id}';
//$id_user = "513";

Here is my problem!
If I manually set the user id ($id_user = "513";), get the fields I want. If you use ($id_user = '{$ my->id}';) you will not get the fields!
However, if you put a variable with '{$my->id}', you will find id ...

What am I doing wrong?
 
Is your code "inline" (in a text box in the settings) or in a file?

If it's in a file, you can't use placeholders.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top