Jump to content

Populating dropdown boxes


cadac

Recommended Posts

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.

Link to comment
Share on other sites

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'];
}

 

Link to comment
Share on other sites

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>";
?> 

Link to comment
Share on other sites

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

 

update.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.