TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,982
  • Total Topics: 21,320
  • Online today: 2,539
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 2566
  • Total: 2566

Member Dropdown Selection

Started by TimUSA, December 27, 2007, 06:35:33 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TimUSA

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);
}

MinasC

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

TimUSA

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.


TimUSA

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?

JPDeni

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>");

This website is proudly hosted on Crocweb Cloud Website Hosting.