cadac Posted December 14, 2011 Share Posted December 14, 2011 I am trying to figure out how to display member records after selecting it from the box. I've got the dropdown box working which retrieves the members name but cannot figure out how to populate that members details on the same page? I'm using php/mysql and although I want to display the records I also want a user to update that record aswell, creating it for administrators to update accounts? Any help would be appreciated I've researched that ajax or javascript might be helpful but not totally familiar with them. Quote Link to comment https://forums.phpfreaks.com/topic/253166-populating-dropdown-boxes/ Share on other sites More sharing options...
Nodral Posted December 14, 2011 Share Posted December 14, 2011 Not sure about the ajax or javascript, but i'd have the value of the option as an id for the person you are selecting from the drop down box, then when you resubmit the page, run a query against your DB using this reference and this will give you the details you need. ie. to create dropdown $result.="<select name='people'><option value='%'>Select</option>"; $sql="SELECT id, forename, surname FROM people ORDER by surname"; $sql=mysql_query($sql); while($row=mysql_fetch_array($sql)){ $result.="<option value='".$row['id']."'>".$row['forename']." ".$row['surname']."</option>"; } $result .="</select>"; then $sql="SELECT forename, surname FROM employees WHERE id = $_POST['people']"; $sql=mysql_query($sql); while($row=mysql_fetch_array($sql)){ $result=$row['forename']." ".$row['surname']; } Quote Link to comment https://forums.phpfreaks.com/topic/253166-populating-dropdown-boxes/#findComment-1297874 Share on other sites More sharing options...
cadac Posted December 14, 2011 Author Share Posted December 14, 2011 Thanks for the advice, i've managed it using a slightly different piece of code but gets the result i need. Just need to figure out to display single record on the same page without refreshing :/ <?php include ('includes/connect.php'); $query = "select member_id, firstname, lastname from members ORDER BY firstname asc"; $result = mysql_query ($query) or die (mysql_error()); echo "<td><b>Select Member: </b></td> <td><SELECT name=\"member-list\">"; if (mysql_num_rows($result)>0) { while($row=mysql_fetch_array($result)) { echo "<option value='".$row['member_id']."'>".$row['firstname']." ".$row['lastname']."</option>"; } } echo "</SELECT></td>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253166-populating-dropdown-boxes/#findComment-1297901 Share on other sites More sharing options...
cadac Posted December 14, 2011 Author Share Posted December 14, 2011 I've attached a screenshot of the page im try to populate the selected dropdown names. All I want now is to populate that members record into those textboxes as I have an update script ready to go. If you can help you would make my day Thanks Quote Link to comment https://forums.phpfreaks.com/topic/253166-populating-dropdown-boxes/#findComment-1297936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.