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

$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);

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.