News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Select Member names from database

Started by PiGuy, May 15, 2011, 11:15:51 PM

Previous topic - Next topic

PiGuy

How can I select the Member_name column from the Smf_members table, and then display it.
My current code is configured to select the row "name" from a table, but I want to change it (For integration purposes) to read the member_names instead.
Help? :S

mysql_connect($MySQL["host"], $MySQL["username"], $MySQL["password"]);
mysql_select_db($MySQL["database"]);

$query = "SELECT * FROM `" . $MySQL["table"] . "`;";
$Result = mysql_query($query);
$i = 0;
$rows = mysql_num_rows($Result);

while( $row = mysql_fetch_array($Result) ){
print(($i < $rows - 1 ? $row["name"] . "|" : $row["name"]));
$i++;
}

Matthew K.

Try this...
function getMembers()
{
global $smcFunc, $memberList;
$request = $smcFunc['db_query']('', '
SELECT id_member, member_name
FROM {db_prefix}members
WHERE is_approved = {int:approved}',
array(
'approved' => 1,
)
);
$memberList = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$memberList[$row['id_member']] = $row['member_name'];
}
$smcFunc['db_free_result']($request);
}

You'd have to call that function, and then globalize $memberList in the template to use it. In the format of memID->Name

Advertisement: