This is a redone post as my last one contained all of my code and I wanted to simply for the post.
Here is what I am doing:
I show the categories that the user has placed a referral in on the page "my_categoreis.php". The user then can select a category from their list and be taken to the "my_subcategories.php" page. On this page, the intent is that they see all the subcategories in which they have entered a referral for the category they selected from the "my_categories.php" page.
The problem:
No matter what category the user chooses, the results on the "my_subcategories.php" page is the same.
Example:
On the "my_categories.php" page, the categories listed for one user are:
Auto-Car
Baby-Children
Regardless of what the user selects, the "my_subcategory.php" page shows:
Babysitters
This is correct for the selection "Baby-Children" but incorrect for the selection "Auto-Car". If "Auto-Car" is selected, the "my_subcategories.php" page should show:
Insurance
I believe the variable is grabbing the last loop as opposed to correlating to what selection the user has made. Please help me to have the correct subcategory show based upon the selection made by the user.
Here is the code:
my_subcateogy.php
<ul class="pageitem">
<?php $query = "SELECT DISTINCT category FROM referrals WHERE username='$_SESSION[username]' ORDER BY category ASC";
$result = mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$catsel=mysql_result($result,$i,"category");
?>
<li class='menu'><span class='name'>
<a class="noeffect" onclick="document.mycategories.submit();return false" />
<input type="hidden" name="catsel" value="<?php echo $catsel; ?>">
<?php echo $catsel; ?>
</span><span class='arrow'></span></a></li>
<?php $i++; } ?>
</ul>
my_subcategory.php
include "include/session.php";
include "fb-config.php";
$catsel=$_POST["catsel$i"];
$catsel=mysql_real_escape_string($catsel);
<ul class="pageitem">
<?php $query = "SELECT DISTINCT subcategory FROM referrals WHERE username='$_SESSION[username]' AND category='$catsel' ORDER BY subcategory ASC";
$result = mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
mysql_close();
$i=0;
while ($i < $num) {
$subcatsel=mysql_result($result,$i,"subcategory");
?>
<li class='menu'><span class='name'>
<a class="noeffect" onclick="document.mysubcategories.submit();return false" />
<input type="hidden" name="subcatsel" value="<?php echo $subcatsel; ?>">
<?php echo $subcatsel;
?>
</span><span class='arrow'></span></a></li>
<?php $i++; } ?>
</ul>