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!

How to use if statement to select a dropdown

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi folks

Ok I have two drop down tables both are pulling from an

mysql database. Now what I want to do is this, when you

select an option in dropdown one it will determine whether

dropdown 2 or 3 is displayed

eg if secondary_exam_id == 1 then see dropdown 2

but if secondary_exam_id == 2 then dropdown 3 is displayed

Here is the code

// DROP DOWN 1


echo'<table align="center">';

echo'<tr>
<td colspan="2" class="labelcell"><label for="secondary_exam_id">Select Exam:</label></td>';

echo'<td colspan="2" class="fieldcell2">
<select name="secondary_exam_id">';

$query_result = mysql_query ('SELECT * FROM secondary_exam_type ORDER BY secondary_exam_id');

while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))

{
echo "<option value=\"$row[0]\">$row[1]</option>\n";
}

echo'</select></td>';

echo'</tr>';



// DROP DOWN 2



echo'<tr>
<td colspan="2" class="labelcell"><label for="junior_subject_id">Select Subject:</label></td>';

echo'<td colspan="2" class="fieldcell2"><select name="junior_subject_id">';

$query_result = mysql_query ('SELECT * FROM junior_subjects ORDER BY junior_subject_id');

while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))

{
echo "<option value=\"$row[0]\">$row[1]</option>\n";
}

echo'</select></td>';

echo'</tr>';




// DROP DOWN 3


echo'<tr>
<td colspan="2" class="labelcell"><label for="leaving_subject_id">Select Subject:</label></td>';

echo'<td colspan="2" class="fieldcell2"><select name="leaving_subject_id">';

$query_result = mysql_query ('SELECT * FROM leaving_subjects ORDER BY leaving_subject_id');

while ($row = mysql_fetch_array ($query_result, MYSQL_NUM))

{
echo "<option value=\"$row[0]\">$row[1]</option>\n";
}

echo'</select></td>';

echo'</tr>';


Hope u understand what i'm getting at.

Tks alot

Gaz
 
Ok I have two drop down tables both are pulling from an mysql database. Now what I want to do is this, when you select an option in dropdown one it will determine whether dropdown 2 or 3 is displayed.

Actually, this is a client-side script, not server side. You will obtain this with javascript. Ask this in the javascript forum.
 
Yes, but i do not want to use javascript on my site there

must be any easier way to do this with a if statement.

Is there any easier way to call information from a mysql

database with php. Don't really know any javascript anyway

TKs

Gaz
 
yeah, reloading the page each time the user select an option.

I insist, javascript is your solution.
 
Ok

Can you give me any idea of how it might look

Tks alot

Gaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top