I am having an issue with the WHILE LOOP variable being past via POST to the next page. The first page provides the query results for all the categories in which a user has provided a referral. When the user selects one of the listed categories, it is supposed to take them to the next page displaying the those subcategories in which the user has provided a referral. From there, the user will be able to select a subcategory to drill down on a particular referral.

The problem: When the query runs on the first page (my_referrals.php) the returned result is

"Auto-Car"
"Baby-Children"

This is correct. However, whether they select either of the two, the results displayed on the next page (my_subcategories) are the same.

"Babysitters"

The "Auto-Car" should result in "Insurance on (my_subcategories). I am sure this has something to do with the variable grabbing the last loop regardless of the selection, but how can code it so that the variable is dependent upon the selection made by the user.

Here is the code for page one and two:

Page One:

<?php
include "include/session.php";
include "fb-config.php";
include "check.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
		<title>friendhelper</title>
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="index,follow" name="robots" />
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<link href="http://www.friendhelper.com/css/style.css" rel="stylesheet" media="screen" type="text/css" />
		<script src="http://www.friendhelper.com/javascript/functions.js" type="text/javascript"></script>
		<meta content="iPad,iPhone,iPhone4,referrals,friends,networking,app" name="keywords" />
		<meta content="socially give and receive referrals with friends for products and services with this add" />
	</head>
	<body>
		<div id="topbar">
			<div id="leftnav"><a href="home.php"><img alt="home" src="images/home.png" /></a><a href="friends.html">Friends</a></div>
			</div>
			<div id="rightnav"><a href="page-coming-soon.php">Friend Request</a></div>
		<div id="content">

			<ul class="pageitem">
			<li class="menu"> <a class="noeffect" onclick="location.href='referral_input.php'"> <img alt="my account" src="http://friendhelper.com/thumbs/myaccount-thumb.png" /><span class="name">Add a Referral</span><span class="arrow"></span></a></li>
			</ul>
			<span class="graytitle">My Categories</span>
			<form method='POST'  name="mycategories" action='my_subcategories.php'>
				<fieldset>
					<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_numrows($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>
				</fieldset>
			</form>
		</div>
	</body>
</html>

Page Two:

<?php
include "include/session.php";
include "fb-config.php";
$catsel=$_POST['catsel'];
$catsel=mysql_real_escape_string($catsel);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0" />
		<title>friendhelper</title>
		<meta content="yes" name="apple-mobile-web-app-capable" />
		<meta content="index,follow" name="robots" />
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<link href="http://www.friendhelper.com/css/style.css" rel="stylesheet" media="screen" type="text/css" />
		<script src="http://www.friendhelper.com/javascript/functions.js" type="text/javascript"></script>
		<meta content="iPad,iPhone,iPhone4,referrals,friends,networking,app" name="keywords" />
		<meta content="socially give and receive referrals with friends for products and services with this add" />
	</head>
	<body>
		<div id="topbar">
			<div id="leftnav"><a href="home.php"><img alt="home" src="images/home.png" /></a><a href="friends.html">Friends</a></div>
			</div>
			<div id="rightnav"><a href="page-coming-soon.php">Friend Request</a></div>
		<div id="content">

			<ul class="pageitem">
			<li class="menu"> <a class="noeffect" onclick="location.href='referral_input.php'"> <img alt="my account" src="http://friendhelper.com/thumbs/myaccount-thumb.png" /><span class="name">Add a Referral</span><span class="arrow"></span></a></li>
			</ul>
			<span class="graytitle"><?php echo $catsel ;?></span>
			<form method='POST'  name="mysubcategories" action='my_referral.php'>
				<fieldset>
					<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_numrows($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="catsel" value="<?php echo $subcatsel; ?>">
	<?php	echo $subcatsel; ?>
						</span><span class='arrow'></span></a></li>
	<?php	$i++;	} ?>
					</ul>
				</fieldset>
			</form>
		</div>
	</body>
</html>

on line 38 on page ONE you have: mysql_numrows - isnt that mysql_num_rows (with underscore..)?

on line 39 on page TWO you have: mysql_numrows - isnt that mysql_num_rows (with underscore..)?

I havent checked the entire document properly, but saw that when running thrugh your code.

But failing to get the mysql_num_rows, result into your variable($num), doesnt give your script anything to work with.

Maybe another time (and it might just be me... ) :-) you could just post the code that gives you an headache: instead of the entire page - so it is easier to check for people viewing/trying to help/find the problem :-)

Klemme

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.