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
https://forums.phpfreaks.com/topic/253166-populating-dropdown-boxes/
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'];
}

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.