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!

dropdown session

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Slainte,

Could someone help me the the following question.

I have a dropdown list which is pulling from a mysql

database.

What i want to do is keep the item that is selected in the

dropdown visible to the user if they navigate back to check

their inputs. I am using sessions but cannot figure out to

apply them to the code for dropdowns

Here's my code

----------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------

Hence I want to make $row[1] a session variable to that it

stays visible until the form is submitted.

Here's the entire code so that it makes more sense

----------------------------------------------------------------------------------------------------------------------

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>';

----------------------------------------------------------------------------------------------------------------------

Tks in advance i know you guys can help

 

You might want to try putting this line at the top of your php:

Code:
header("Cache-control: private");

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
 
OK but what will that do will i not still have to register

the array $row[1] as a session

Tks
 
session_start(); at the top, then you need to assign the variables to a session variable or two.

$_SESSION['foo'] = $row['bar'];

You can then use:
if(!($_SESSION['foo'])) {
//session is not set
}
else {
// session is set
}

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top