Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown values not populating for existing record

Status
Not open for further replies.

dnayana

Programmer
Nov 14, 2002
53
US
First, thanks in advance to anyone who is able to assist me.

I'm a newbie to PHP; this is my first APP. (I normally use ColdFusion to develop a web app -- if you know of any sites or books that provide the PHP equivalent syntax/tags/etc. to Coldfusion, please let me know. Trying to make my transition a little easier. [smile])

The problem I am having is, that the select box displays ONLY the selected value within an existing record; it doesn't display ALL the values (i.e. to allow the user to change his/her previous selection) along with his/her original selected value.

Not sure what I have wrong ... did some research across various forums, but have yet to find a resolution.

Code:
 ...within top portion of page
//retrieve the data from the database
//odbc_fetch_row: Fetch a row 
  while(@odbc_fetch_row($qryresult))
     { 	
       $intCompany = odbc_result($qryresult, "intCompany");
     ...
     }


Code:
<tr>
	<td class="rowlbl">Company</td>
	<td><select name="intCompany">		
		<option value="">
		<?
	//the SQL statement that will query the database 
	  $qryCompany = "select * from tblCompany order by txtCompany ASC"; 

	//perform the query 
	//odbc_exec: Prepare and execute a SQL statement 
	  $qrycompanyresult=odbc_exec($conn, $qryCompany); 
	
	//retrieve the data from the database
	//odbc_fetch_row: Fetch a row 
		
			while(@odbc_fetch_row($qrycompanyresult)){ 
			//odbc_result: Get result data
		  $ctrCompany = odbc_result($qrycompanyresult, "ctrCompany");
		  $txtCompany = odbc_result($qrycompanyresult, "txtCompany");
			if(!$_GET[ctrCandidate]){
				//new record	
				echo "<option value=\"$ctrCompany\">$txtCompany</option>";
			} else {
				//existing record
				if($intCompany == $ctrCompany) {
				echo "<option value=\"$ctrCompany\" 	SELECTED>$txtCompany</option>";
				}
			}
}
?>
	</select>
	</td>
</tr>

Again, any assistance is greatly appreciated!

Thanks,
[ponytails2] Nicole
 
I figured it out myself.

This is for anyone else who may be having the same issue.

I changed ...

Code:
    if(!$_GET[ctrCandidate]){
	//new record	
	echo "<option value=\"$ctrCompany\">$txtCompany</option>";
	} else {
	  //existing record
	  if($intCompany == $ctrCompany) {
	    echo "<option value=\"$ctrCompany\" 	SELECTED>$txtCompany</option>";
	}

... to the following

Code:
  if($intCompany == $ctrCompany) {
	echo "<option value=\"$ctrCompany\" 	SELECTED>$txtCompany</option>";			
	} else {
             echo "<option value=\"$ctrCompany\">$txtCompany</option>";
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top