Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

diokhan

opçao do select box

Recommended Posts

diokhan

Boas,

eu tenho no meu projecto uma COMBO BOX para escolher o cliente e o tipo de projecto que vou inserir na base de dados, e estas duas COMBO BOX são preenchidas com dados da tabela, e queria que ao editar o valor que ficasse seleccionado fosse o valor que esta na base de dados.

por exemplo, eu inseri um projecto com o cliente B, e ao editar, a COMBO BOX esta em ORDER BY client_name, logo a opção que esta seleccionada é A, mas queria que no caso de editar o projecto com o cliente B a opção fosse B, espero ter-me feito perceber.

fica aqui o código que tenho feito:

<tr>
   <td>Client name:</td>
   <td>";
$clients = $projects->GetClient();
echo'<select name="idClient">';
   foreach($clients as $key=>$value)
   {
        echo '<option value="'.$key.'">'.$value.'</option>';
           }		
echo "</select>
   </td>
</tr><tr>
   <td>Project Type:</td>
   <td>";
   require_once ('./functions.php');
   $project_type = new Project;	
   $proj_type = $project_type->GetProjType(); 
   echo'<select name="projectType">';
      foreach($proj_type as $key=>$value)
      {
         echo '<option value="'.$key.'">'.$value.'</option>';
      }
   echo "</select>
   </td>
</tr>


...Join the dark side...and get a free cookie...

Share this post


Link to post
Share on other sites
diokhan

problema resolvido..fica aqui a solução se alguém precisar:

<tr>
				  	<td>Client name:</td>
					<td>";
						$clients = $projects->GetClient();
						echo'<select name="idClient">';
							foreach($clients as $key=>$value)
							{
								$nameClient = $row[NAME_CLIENT];
								if ($value == $nameClient){
									echo '<option value="'.$key.'" SELECTED>'.$value.'</option>';
								}else{
									echo '<option value="'.$key.'">'.$value.'</option>';
								}
		   					}		
						echo "</select>
				</td>
			    </tr><tr>
			    	<td>Project Type:</td>
			    	<td>";
						require_once ('./functions.php');
						$project_type = new Project;	
				    	$proj_type = $project_type->GetProjType(); 
			    		echo'<select name="projectType">';
							foreach($proj_type as $key=>$value)
							{
								$projectType = $row[NAME_PROJECT_TYPE];
								if ($value == $projectType){
									echo '<option value="'.$key.'" SELECTED>'.$value.'</option>';
								}else{
									echo '<option value="'.$key.'">'.$value.'</option>';
								}
				   			}
						echo "</select>
				</td>
			    </tr>


...Join the dark side...and get a free cookie...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.