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?
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?