Forums

query db read login

agostino87 03 Mar, 2017
I want to enter a query in a "db read".
The query must be the user's login.
How can I do ??
thanks
agostino87 03 Mar, 2017
I inserted a "custom code" in the "On Load"

<?php
$user = \JFactory::getUser();
$form->data['user_id'] = $user->username;
?>


I tested these two codes in "conditions" of the "db read"

<?php
$user = \JFactory::getUser();
return array('model id.field' => $user->username);
?>

or

<?php
$user = \JFactory::getUser();
$form->data['field'] = $user->username;
?>


Unfortunately, the query does not work
GreyHead 03 Mar, 2017
Hi agostino87 ,

Then you have something incorrect - there isn't enough information here to give me any idea what that is. If you add a Debugger after the DB Save action you can see the query that is being created.

Bob
Max_admin 03 Mar, 2017
Hi,

Just this code in the db read will do it:

<?php
$user = \JFactory::getUser();
return array('field' => $user->username);
?>


no need for the other code of the on load, unless you use the "user_id" variable.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
agostino87 03 Mar, 2017
i have delete custom code.

i use

<?php
$user = \JFactory::getUser();
return array('agente' => $user->username);
?>


debug DBread this is

Array
(
    [24] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `elenco`.`codice` AS `elenco.codice`, `elenco`.`nomeCliente` AS `elenco.nomeCliente`, `elenco`.`codicenome` AS `elenco.codicenome`, `elenco`.`agente` AS `elenco.agente`, `elenco`.`manager` AS `elenco.manager` FROM `anagrafica` AS `elenco` WHERE `elenco`.`agente` = 'tuttoilmondo' ORDER BY `elenco`.`codicenome`
                        )

                )

        )

)


I there is a doubt, there is no difference between upper and lower case in the query?
GreyHead 03 Mar, 2017
Hi agostino87,

Both column names and values are case sensitive.

Your MYSQL WHERE clause looks OK here
WHERE `elenco`.`agente` = 'tuttoilmondo'


Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger