Need MySQL help (again)

Started by Erica McLane, Thu 22/05/2003 14:55:39

Previous topic - Next topic

Erica McLane

I have this table: (not real names)

id | username | password |  number
--------------------------------------------------
1 | john           | password_j  |  43
2 | mary          | password_m | 453
3 | peter         |  pass_p |  4343
4 | ags           | pass_a  | 332

I know how to select everything and put in into one drop-down style listbox. Now I need a script that will get the 'number' value for the selected 'username' in the listbox.
Got it? Or no?
OK.
Example: The user selects the 'peter' value in the listbox for username. I want a variable - $number to be filled with the contents of the number column for the name peter, in this case it is 4343.
Another example: The user selects 'ags' and clicks the Submit button. Then the $number variable should be filled with the number 332 (in the 'ags' level, with the same id). Then a simple echo would be good for the $number variable.

Got it now?

Really need help for this thing.
Thanks in advance.

n3tgraph

Could you post the mysql_query and the form script?

this could still go several ways, and I don't want to post unnecessary script ;)
* N3TGraph airguitars!

Erica McLane

OK. Here is it:

<?
include("config.php");
$db = mysql_connect("$host", "$username", "$password");
@mysql_select_db("$databasename", $db);
?>

<form>
<select name="usern">
<?
$query="SELECT * FROM $tablename usern";
$result=mysql_query($query);

$num=mysql_numrows($result);

$i=0;

while ($i < $num) {
$usern=mysql_result($result,$i,"usern");

echo "<option value=\"$usern\">$usern</option>";

++$i;
}
?>
</select>


<input type="submit" value="Submit"><input name="action" type="hidden" value="add">
<input type="reset" value="Clear">



So I want the number to appear when the user clicks the Submit button.

SMF spam blocked by CleanTalk