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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selection drop-down box 1

Status
Not open for further replies.

andy98

Programmer
Jul 7, 2000
120
GB
I have a selection box with a list of SALES people in, that is pulled from a Database table and i later store the SALES_ID in the ORDER table:

Code:
$query = "SELECT * FROM sales ORDER BY sales_person ASC";
$result = mysql_query($query) or die (mysql_error()); 

echo "<select name='sales_id' id='$sales_id'>";
   
     while ($row = mysql_fetch_row($result)){
                 $sales_id = $row[0];
                 $sales_person = $row[1];
				 $sales_office = $row[2];
                 print("<option value=\"$sales_id\">$sales_person, $sales_office</option>\n");
          }

This is fine, however - I use the selection box in an ORDER table where I store the SALES_ID to associate a SALES_PERSON with an Order.

What I can't figure out is how I would EDIT the Order and have the SALES_PERSON selected as default from the selection box!


 
<select name='sales_id' id='$sales_id'>
<option value="1">sales_person, sales_office</option>
<option value="2" selected>sales_person, sales_office</option>
<option value="3">sales_person, sales_office</option>

Add an "if" statment.. if the sales_id is the same as the row add the "selected" in the option tag.

hope this helps.
 
I have got this far - but cannot get this PRINT line to parse:

Code:
echo "<select name='sales_id' id='$sales_id'>";
   
     while ($row = mysql_fetch_row($result)){
                 $sales_id     = $row[0];
                 $sales_person = $row[1];
				 $sales_office = $row[2];
[b]print("<option value=\"$sales_id\" if( $row['sales_id']== $_GET['sales_id'] ){'selected'}> $sales_person, $sales_office</option>");[/b]

Am I on the right lines?




 
hold on...

print("<option value=\"$sales_id\" if( $row['sales_id']== $_GET['sales_id'] ){'selected'}> $sales_person, $sales_office</option>");

is not correct.. it should be:

Code:
print("<option value=\"$sales_id\" ");

if( $row['sales_id']== $_GET['sales_id'] )
   print("selected");

print("> $sales_person, $sales_office</option>");
 
That parses successfully now thanks!

But the selection box doesn't SELECT the correct sales person.

It just displays the default list.

Any ideas as to why?

I know that the correct variable SALES_ID is brought into the page.

 
The html code returns:
Code:
<select name='sales_id' id='2'>
<option value="4" > Deb, UK</option>
<option value="8" > Dave, UK</option>
<option value="2" > Phil, UK</option>
</select>

Option value 2 should be displayed as SELECTED but it doesn't!

 
ok, replace the if:

if( $row['sales_id']== $_GET['sales_id'] )
print("selected");

if( $sales_id == $_GET['sales_id'] )
print("selected");

I didn't notice that you have $sales_id = $row[0];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top