PHP Dropdown Question

Hi there,

I am new to php and so I am having an issue with drop. I want my dropdown to display firstname and lastname together, but I am not sure how.

Here is my query at present:
=================================================================
<?php
                                    
                                    $query1 = "select firstname, lastname from staff ";                                    
                                    mssql_query($query1) or die('Error, query failed');            
                                    $result1 = mssql_query($query1);
                                    
                                    
                                    while($row1 = mssql_fetch_array($result1))
                                    {
                              ?>
                        <option value="<?php echo $row1['firstname'];?>"><?php echo $row1['firstname'];?>                        </option>
                 
                        <?php }?>
======================================================================


Any idea?

Thanks,
fasulnAsked:
Who is Participating?
 
Pratima PharandeConnect With a Mentor Commented:
<?php
                                   
                                    $query1 = "select firstname, lastname from staff ";                                    
                                    mssql_query($query1) or die('Error, query failed');            
                                    $result1 = mssql_query($query1);
                                   
                                   
                                    while($row1 = mssql_fetch_array($result1))
                                    {
                              ?>
                        <option value="<?php echo $row1['firstname']. ' ' . $row1['firstname'];?>">                      </option>
                 
                        <?php }?>
0
 
fasulnAuthor Commented:
Hi there,

You query will still only show 'firstname'.

Please advise.

Thanks,
0
 
Pratima PharandeCommented:
<?php
                                   
                                    $query1 = "select firstname, lastname from staff ";                                    
                                    mssql_query($query1) or die('Error, query failed');            
                                    $result1 = mssql_query($query1);
                                   
                                   
                                    while($row1 = mssql_fetch_array($result1))
                                    {
                              ?>
                        <option value="<?php echo $row1['firstname']. ' ' . $row1['lastname'];?>">                      </option>
                 
                        <?php }?>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
fasulnAuthor Commented:
I replaced your code with mine and I am only displaying blanks now. drop
0
 
Lukasz ChmielewskiCommented:
<option value="<?php echo $row1['firstname']. ' ' . $row1['lastname'];?>">
<?php echo $row1['firstname']. ' ' . $row1['lastname'];?>
</option>
0
 
Atique AnsariConnect With a Mentor Commented:
You can use this code. Just replace 'user_id' with primary key of staff table.
<?php
	$query1 = " SELECT user_id, firstname, lastname FROM staff ";
	mssql_query($query1) or die('Error, query failed');
	$result1 = mssql_query($query1);
	
	while( $row1 = mssql_fetch_array($result1) )
	{
?>
	<option value="<?php echo $row1['user_id'];?>">
		<?php echo $row1['firstname'].'&nbsp;'.$row1['firstname'];?>
	</option>
<?php
	}
?>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.