Code: Select all
$query = "SELECT *, (SELECT groupid FROM intranet.users_associatedgroups WHERE userid=intranet.users.id) AS groupid FROM intranet.users WHERE id={$req_vars['id']}";
$info = pg_fetch_assoc(pg_query($db, $query));
Moderator: General Moderators
Code: Select all
$query = "SELECT *, (SELECT groupid FROM intranet.users_associatedgroups WHERE userid=intranet.users.id) AS groupid FROM intranet.users WHERE id={$req_vars['id']}";
$info = pg_fetch_assoc(pg_query($db, $query));
Code: Select all
SELECT u.*, uag.groupid
FROM intranet.users u
JOIN intranet.users_associatedgroups uag ON u.id = uag.userid
WHERE u.id = <ID>Code: Select all
$query = "SELECT users.*,users_associatedgroups.groupid
FROM users
LEFT JOIN users_associatedgroups ON users_associatedgroups.userid=users.id
WHERE users.id={$req_vars['id']}";pytrin wrote:Edit: Oops, tasairis beet me to itCode: Select all
$query = "SELECT users.*,users_associatedgroups.groupid FROM users LEFT JOIN users_associatedgroups ON users_associatedgroups.userid=users.id WHERE users.id={$req_vars['id']}";
Code: Select all
{foreach from=$grps item=grp}
<option value="{$grp.id}" {if $info.groupid == $grp.id}SELECTED{/if}>{$grp.description}</option>
{/foreach}
yesJade wrote:Are you getting multiple results for a single user in the data the query returns? I would check the query data...
Code: Select all
SELECT * from intranet.users_associatedgroups WHERE userid=64; Code: Select all
userid | groupid
--------+---------
64 | 1
64 | 2
Code: Select all
<select multiple size=5>
<option value="1"SELECTED>1</option> //this is WRONG, some browsers *cough* namely IE *cough* won't read this properly
<option value="1" SELECTED>1</option> //this one has space so everything is fine and dandy
</select>
I didn't understand the question, but the query fetches all the groups related to the user in question. Is it not what you wanted?this is working, but the associatedgroups table is populating a MULTIPLE dropdown select box. With this query, it only selected 1 of the options in the dropdown, even when the user is in MULTIPLE groups?
yeah it is spaced properlyJade wrote:Make sure you have a space between the <option value="something" and the word selected. Also, make sure that you have multiple in your select tag.
Code: Select all
<select multiple size=5> <option value="1"SELECTED>1</option> //this is WRONG, some browsers *cough* namely IE *cough* won't read this properly <option value="1" SELECTED>1</option> //this one has space so everything is fine and dandy </select>
Code: Select all
<select name="groups[]" id="groups" MULTIPLE>
<option value="">-- select group(s) --</option>
{foreach from=$grps item=grp}
<option value="{$grp.id}" {if $info.groupid == $grp.id} SELECTED{/if} >{$grp.description}</option>
{foreachelse}
<option>[ERROR]No Groups Exist?</option>
{/foreach}
</select>
Code: Select all
$query2 = "SELECT u.*, uag.groupid
FROM intranet.users u
JOIN intranet.users_associatedgroups uag ON u.id = uag.userid
WHERE u.id={$req_vars['id']}";
$info = pg_fetch_assoc(pg_query($db, $query2));
$smarty->assign('info', $info);
//User Groups
$grp_sql = pg_query($db, "SELECT * FROM intranet.users_groups");
while ($groups = pg_fetch_assoc($grp_sql)){
$grps[] = $groups;
}
$smarty->assign('grps', $grps);
Code: Select all
$info['uag.groupid']Code: Select all
SELECT uag.groupid AS groupid ...