I am having trouble figuring out how to implement this. I am returning user data to populate a profile page where the user can edit information. It fills in fields like name, job, title, etc. I have a field called Interests where I grab the Main Interests before I execute the code returning the user data. So I store those in an array and then return them to populate the first one. But the second is dependent on which choice they make. How should I go about filling that second box (I know the code that I will use I asking about how I should store the data to be retrieved. Because I cant execute a sql command inside the while loop, and I dont really want to return every sub-interest that just seems like a waste of resources)
Code for returning user data:
$result = mysql_query("SELECT * FROM WHERE U.uid = '$uid';");
while($row = mysql_fetch_assoc($result)){
Code for Adding Interests:
<option selected value="">Select an Interest</option>
<?
for ($i=0; $i<$setintcount; $i++)
{
if($setinterests[$i] == $interests[$i])
{
echo "<option selected value='$setinterests[$i]'>$setinterests[$i]</option>";
}
else
{
echo "<option value='$setinterests[$i]'>$setinterests[$i]</option>";
}
}
?>
</select>
Sub-Interest: <select name="selectedsubint" id="selectedsubint" onchange="checkval(id);">
<option selected value="">Select an Sub-Interest</option>
</select>
The easiest way is load all sub-interests, but you wrote its waste of resources. It depends on how much sub-interest you will have stored.
Another solution is to refresh page and get needed sub-interests, but it seems rough to me.
Elegant solution could be by using AJAX to get sub-interest. Throu AJAX you could call page that will generate right sub-interests for selected main-interest.