[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

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,
0
fasuln
Asked:
fasuln
2 Solutions
 
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['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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 AnsariCommented:
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now