Jump to content

Php To Select Different Column For Option Value


ncurran217

Recommended Posts

I would like to have my option value a different column then the display part of the option. I would like the value part to be the column ForteID and the display part to be the Rep column of my SQL Query. Is this possible?

 

<?php 
$serverName = 'SRB-Nick_Desktop\SQLEXPRESS';
$connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456');
$connection = sqlsrv_connect($serverName, $connectionInfo);


$query = ' SELECT ForteID, Rep
  FROM Reps
  ORDER BY Rep';


$result = sqlsrv_query($connection,$query);


if (!$result)


{
$message = 'ERROR: ' . sqlsrv_errors();
return $message;
}
else
{ 
$i = 0;
while ($i < sqlsrv_num_rows($result))
{
 $meta = sqlsrv_fetch($result, $i);
 echo '' . $meta->name . '';
 $i = $i + 1;
}
echo '<select name="ForteID" id="ForteID">';
while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC ))
{
 $count = count($row);
 $y = 0;

 while ($y < $count)
 {
  $c_row = current($row);
  echo '<option value="[color=#ff0000]' .$c_row. '[/color]";>[color=#00ff00]' .$c_row.'[/color]</option>';  
  next($row);
  $y = $y + 1;
 }
 }
echo '</select>';
sqlsrv_free_stmt ($result);
}
sqlsrv_close( $connection);
?>

Link to comment
Share on other sites

$serverName = 'SRB-Nick_Desktop\SQLEXPRESS';
$connectionInfo = array('Database'=>'cslogs', 'UID'=>'cslogslogin', 'PWD'=>'123456');
$connection = sqlsrv_connect($serverName, $connectionInfo);

$query = "SELECT ForteID, Rep
	  FROM Reps
	  ORDER BY Rep";
$result = sqlsrv_query($connection,$query);

if (!$result)
{
   return 'ERROR: ' . sqlsrv_errors();
}

echo "<select name='ForteID' id='ForteID'>\n";
while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
{
  echo "<option value='{$row['ForteID']}'>{$row['Rep']}</option>\n";  
}
echo "</select>\n";

sqlsrv_free_stmt ($result);
sqlsrv_close( $connection);

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.