PHP echo using same syntax as form select

I have a form select that dynamically pulls from a database a list of contractors. This works great and matches the contrID for that record as the selected value

			  <select name="S_contrID" id="S_contrID">
                <option value="">---</option>
do {  
                <option value="<?php echo $row_WADADynListsys_users['userID']?>"<?php if (!(strcmp($row_WADADynListsys_users['userID'], $row_WADAsys_client["contrID"]))) {echo "selected";} ?>><?php echo $row_WADADynListsys_users['fname']?> <?php echo $row_WADADynListsys_users['lname']?></option>
} while ($row_WADADynListsys_users = mysql_fetch_assoc($WADADynListsys_users));
$rows = mysql_num_rows($WADADynListsys_users);
if($rows > 0) {
mysql_data_seek($WADADynListsys_users, 0);
$row_WADADynListsys_users = mysql_fetch_assoc($WADADynListsys_users);

Open in new window

How do I strip out this functionality to be a simple echo statement showing the correct fname and lname for the record?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Is it showing something incorrect now?
Ray PaseurCommented:
Maybe something like this?
while ($row_WADADynListsys_users = mysql_fetch_assoc($WADADynListsys_users))
    echo $row_WADADynListsys_users['fname'];
    echo $row_WADADynListsys_users['lname'];

Open in new window

pda4meAuthor Commented:
no luck Ray.  Right now it just echo's out all the names in a loop even with your example.  Here is the original recordset:

$maxRows_WADADynListsys_users = 1000;
$pageNum_WADADynListsys_users = 0;
if (isset($_GET['pageNum_WADADynListsys_users'])) {
  $pageNum_WADADynListsys_users = $_GET['pageNum_WADADynListsys_users'];
$startRow_WADADynListsys_users = $pageNum_WADADynListsys_users * $maxRows_WADADynListsys_users;

mysql_select_db($database_redicare, $redicare);
$query_WADADynListsys_users = "SELECT userID, fname, lname FROM sys_users WHERE userGroupID = 3 ORDER BY lname";
$query_limit_WADADynListsys_users = sprintf("%s LIMIT %d, %d", $query_WADADynListsys_users, $startRow_WADADynListsys_users, $maxRows_WADADynListsys_users);
$WADADynListsys_users = mysql_query($query_limit_WADADynListsys_users, $redicare) or die(mysql_error());
$row_WADADynListsys_users = mysql_fetch_assoc($WADADynListsys_users);

if (isset($_GET['totalRows_WADADynListsys_users'])) {
  $totalRows_WADADynListsys_users = $_GET['totalRows_WADADynListsys_users'];
} else {
  $all_WADADynListsys_users = mysql_query($query_WADADynListsys_users);
  $totalRows_WADADynListsys_users = mysql_num_rows($all_WADADynListsys_users);
$totalPages_WADADynListsys_users = ceil($totalRows_WADADynListsys_users/$maxRows_WADADynListsys_users)-1;

Open in new window

Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Ray PaseurCommented:
What criteria do you want to use to filter out the names?  We might add this in an "if()" statement.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bernie BsenChef de cuisineCommented:
why don't you make it a little bit easier to read like:

$optionstring = "<option value=\"\">---</option>";
while ($row_WADADynListsys_users = mysql_fetch_assoc($WADADynListsys_users));
   $row_WADADynListsys_users = mysql_fetch_assoc($WADADynListsys_users);
   $optionstring.="<option value=\"".$row_WADADynListsys_users['userID'];
   if (!(strcmp($row_WADADynListsys_users['userID'], $row_WADAsys_client["contrID"]))) {
      $optionstring.= " selected";
   $optionstring.=$row_WADADynListsys_users['fname']." ".$row_WADADynListsys_users['lname'];
              <select name="S_contrID" id="S_contrID"><?php echo $optionstring ?></select>

pda4meAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.