• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Searching for a user starting with.....

aussiewarrior

New Member
Hey guys,

Can you please tell me how icould get all the users in my database added to a combo box when a person clicks on a letter.

e.g when they click on A all users starting with a should fill the box.

Cheers
 
do you know php ?

to get a combo box of the users, I would use something similar to
PHP:
<?
include 'dBconnect.php'; # Or whatever your database connection is stored in
# or the connection strings, either way, you need a connection

$i = 0; # for creating loops ...
$users = mysql_query("SELECT * FROM users"); # to get the user info into a var
$num = mysql_num_rows($result); # to tell the loop when to stop

echo "<option name=\"users\">";
while ($i < $num) { # begin looping
$user = mysql_result($result, $i, 'name_field'); # get username into a var
echo "<option value=" . $name . ">" . $name . "</select>\n";
$i++; # to continue the loop
}
echo "</option>\n";
?>

Javascript could do the selections, or you could use regular expressions to exclude data from the array by replacing
PHP:
<?
echo "<option value=" . $name . ">" . $name . "</select>\n";
?>

with
PHP:
<?
if ( preg_match("/^" . $_GET['begin'] . "/i", $name) ) {
echo "<option value=" . $name . ">" . $name . "</select>\n";
}
?>
Where $_GET['begin'] is the letters you wanna list ..... like script.php?begin=a

clearly it's not tested, but that's how ya do it anyways ....
 
Back
Top