I am creating a report function were a manager can look up amendments to a user rota which is a mySQL table. This contains 5 columns Unique_ID ( Auto Increment), UserID(13 digit number), Date effected(Unix date), Date added(Unix date), Added_by(13 digit number).
To select the the correct data i was populating a drop down from another table which contains username and UserID ( a 13 digit number) however i am stuck with how to select the name ( as no one can remember all staff numbers) and it POST the corresponding user id to the next query.
<form action="<?=$_SERVER['php_SELF']?>" method="get">
<?
$loc = $usersite->UserLocation();
$username = "Uname";
$password = "Pword";
$hostname = "Hname";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db("DBname",$dbhandle)
or die("Could not select database");
$query="SELECT name FROM `login1st` WHERE `Location` = '$loc'";
$result = mysql_query ($query);
echo "<select name=category value=''></option>";
while($nt=mysql_fetch_array($result)){
echo'<option value="'.$nt['name'].'">'.$nt['name'].'</option>';
}
echo "</select>";
?>
<input type="submit" value="Search" class="buttons2">
</form>
this work fine and i have a drop down box with all staff names, is there a way to get the associated userid from the selection to a separate query? E.G
SELECT * FROM `$loc` WHERE `User_id` = (query result from drop down)
i am using the PHP_SELF as the result, I am hoping, will go into a table below the drop down. i am open to any other ways of doing this. Thanks in advance.
in the value-section you can define what to submit. So just change your query to get the UserId as well
and then just output the id in your selectbox: