TinyPortal

Development => Block Codes => Topic started by: TimUSA on December 27, 2007, 06:35:33 PM

Title: Member Dropdown Selection
Post by: TimUSA on December 27, 2007, 06:35:33 PM
Thanks to all that helped with this hopefully someone else finds it useful.

To customize this for your purposes change the member group numbers.

$query = "SELECT `memberName` FROM `smf_members` WHERE `ID_GROUP` IN (1, 9, 10, 11, 13) ORDER BY `memberName`;";
$result = mysql_query($query);


echo'
<SELECT id="name" name="name" style="WIDTH: 160px" value ="';
echo '" />';

if(mysql_num_rows($result)) {
// we have at least one user, so show all users as options in select form
while($row = mysql_fetch_row($result))
{
print("<option value=\"$row[0]\">$row[0]</option>");
}
} else {
print("<option value=\"\">No user in this group</option>");
mysql_data_seek($result, 0);
}
Title: Re: Member Dropdown Selection
Post by: MinasC on December 27, 2007, 06:59:47 PM
the list works but it doesn't really do anything ! maybe if it would get you to the selected member's profile , or (even better) it would show underneath the list a short profile of the member ...
Title: Re: Member Dropdown Selection
Post by: TimUSA on December 27, 2007, 07:12:00 PM
That would be up to you...this is just getting the name. you could then use $_POST['name'], or $_GET['name'] to do what ever you wanted.
Title: Re: Member Dropdown Selection
Post by: MinasC on December 29, 2007, 09:07:08 PM
ok , thnx !
Title: Re: Member Dropdown Selection
Post by: TimUSA on January 04, 2008, 02:49:23 AM
have a quick question regarding this. I realized when I created this that I wanted to get a list of names in a dropdown list to insert into a txt field. now what I am realizing as I advance further in the project that I am working on that I need the names to be printed, but the value to be ID_MEMBER, as that is the primary key to be shared in other tables. anyone want to have a stab at this?
Title: Re: Member Dropdown Selection
Post by: JPDeni on January 04, 2008, 12:04:37 PM
Change


$query = "SELECT `memberName` FROM `smf_members` WHERE `ID_GROUP` IN (1, 9, 10, 11, 13) ORDER BY `memberName`;";


to


$query = "SELECT `memberName`, `ID_MEMBER` FROM `smf_members` WHERE `ID_GROUP` IN (1, 9, 10, 11, 13) ORDER BY `memberName`;";


and change


print("<option value=\"$row[0]\">$row[0]</option>");


to


print("<option value=\"$row[1]\">$row[0]</option>");