Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How To make SQL Query Select Option Results

Author  Topic 

jdsmith8
Starting Member

11 Posts

Posted - 2014-07-12 : 16:36:20
Hi All,

I have a Managers table in my SQL DB and it has a ManagerID, MgrName and MgrPhoto field base...

I can code a form with a select button that displays a drop down with the managers in it as choices, but am a little confused as to how I would make the PHOTO (MgrPhoto) change to the corresponding ManagerID that is selected from that option drop down since the SELECT CODE in the form only queries the ManagerID / MgrName combo for the choice.. The photo is below that drop down box and does anyone know how to make it change to whatever photo is assigned to the selected ManagerID / MgrName ???

Here is the form code with query :

<form enctype="multipart/form-data" action="updatemanagerphoto.php" method="POST"> 
<select name="ManagerID" id="manager" style="width:400px" class="form_textbox">
<?

$db_connect = mysql_connect($db_host, $db_username, $db_password);
mysql_select_db($db_name, $db_connect) || die(mysql_error());

$sql_query = "SELECT * FROM Managers ORDER BY MgrName ASC";
$result = mysql_query($sql_query) or die(mysql_error());
while($row = mysql_fetch_array($result)){

$row = decode_array($row);
$ManagerID = $row['ManagerID'];
$MgrName = $row['MgrName'];
$MgrPhoto = $row['MgrPhoto'];

?>
<option value="<?= $ManagerID; ?>"><?= $MgrName; ?></option>
<?

}
mysql_close($db_connect);


?>
</select>
<br/> <br/>
Current Image (if exists) :<br/>
<?

$db_connect = mysql_connect($db_host, $db_username, $db_password);
mysql_select_db($db_name, $db_connect) || die(mysql_error());

$sql_query = "SELECT MgrPhoto FROM Managers WHERE ManagerID='$ManagerID'";
$result = mysql_query($sql_query) or die(mysql_error()); $sql = mysql_query($query);

while ($row = mysql_fetch_array($query)){
$MgrPhoto = $row['MgrPhoto'];
}

mysql_close($db_connect);

?> <? if (file_exists("../files/mainmanagerphoto/$MgrPhoto")) { ?><img src="../files/mainmanagerphoto/<?= $MgrPhoto ?>" width="200px" height="200px">
<? } ?><br/><br/><br/>
New Manager Photo:
<input type="file" name="photo"><br> <br>
<input type="submit" value="Add">
</form>


James Smith

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-07-13 : 12:17:38
This forum is for MS SQL Server. Your question will be best answered in MySQL or PHP forum.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-07-13 : 12:29:07
How is the path calculated? With the webserver as root?
I can see the path in the webpage is relative.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -