I am trying to select data from 'xxx_user' table, based on the usergroup the user is assigned to EG 'administrator'

Is there any way this could be done? And would it be possible to do it with a cron job?

    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "myDB";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);

    $sql = "SELECT id, name, username, password, emails, FROM $dbname";
    $result = $conn->query($sql);

  • Yes it can be done, and yes, with a cron job too. What have you tried so far? – Lodder Dec 21 '15 at 20:53
  • hi well, i started with a execute command, but then realised that the group assignment for the user was held on another table 'xxx_user_group_map, so i stopped there. i can show you what i have, but it wont work based on what i just said. – user2513528 Dec 21 '15 at 20:55

Yes, but however normally one accesses a Joomla database from inside a Joomla application using the JDatabase object. See FFrewin's link in the comments.

Your example appears to be outside of a Joomla application, so your sql statement should look something like this, updated for your specific database schema, obviously.

SELECT id, name, username, password, email FROM `xxx_users` WHERE `id` in (SELECT `user_id` FROM `xxx_user_usergroup_map` WHERE `group_id` = (SELECT `id` FROM `xxx_usergroups` WHERE `title` = 'Administrator'))

I can't see why you couldn't schedule it to be done by a cron job. For that I suggest a separate question/search on Stack Over flow for: scheduling php scripts.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.