PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Jun 19, 2006 6:28 pm
Good Day Devnet!
I am using a database to populate a menu that uses CSS and JavaScript to create a slide-out sub menu.
It uses one loop to create the categories, and then a loop inside for the subcategories.
The second loop isn't working. It populates the first menu, but then doesn't finish and no other menus are loaded.
I have provided links to working and non working examples in the below code.. thanks a lot for looking.
Code: Select all
echo "<div id='dhtmlgoodies_slidedown_menu'><ul>" ;
// Begin PHP Loop #1 - Works ------->
$sql = "SELECT COUNT(*) FROM var_section_names";
$numrecord = mysql_query($sql);
$numrecords = mysql_fetch_array($numrecord);
$numrecords[0];
$intRecsPerPage=12;
if($_POST["intpage"]=="")
{
$intpage=1;
}
$sql = "SELECT * FROM var_section_names ORDER BY Section_N_Weight ASC";
$result = mysql_query($sql) or die (mysql_error());
for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
{
if($x >= $numrecords[0])
{
break;
}
$sectionresults = mysql_fetch_array($result);
$sectionName = $sectionresults["Section_N_Name"];
$sectionNID = $sectionresults["Section_N_ID"];
echo "<li><a href='#'>$sectionName</a>";
echo "<ul>";
// Begin Static Loop - Works -------> http://www.thevariables.com/_/
echo "<li><a href'#'>Roll Out 1</a></li><li><a href'#'>Roll Out 1</a></li>";
// End Static Loop - Works ------->
// Begin PHP Loop #2 - Doesn't Work -------> http://www.thevariables.com/_/indexBad.php
$sql2 = "SELECT COUNT(*) FROM var_sections WHERE Section_AID = '$sectionNID'";
$numrecord = mysql_query($sql2);
$numrecords = mysql_fetch_array($numrecord);
$numrecords[0];
$intRecsPerPage=12;
if($_POST["intpage"]=="")
{
$intpage=1;
}
$sql2 = "SELECT * FROM var_sections WHERE Section_AID = '$sectionNID' ORDER BY Section_Weight ASC";
$result = mysql_query($sql2) or die (mysql_error());
for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
{
if($x >= $numrecords[0])
{
break;
}
$sectionsresults = mysql_fetch_array($result);
$sectionsPT = $sectionsresults["Section_PT"];
$sectionsID = $sectionsresults["Section_ID"];
echo "<li><a href='#'>$sectionsPT</a></li>";
}
echo "</ul>";
// End PHP Loop #2 - Doesn't Work------->
echo "</li>";
}
// End PHP Loop #1 - Works ------->
echo "</ul>";
Last edited by
$var on Mon Jun 19, 2006 6:32 pm, edited 1 time in total.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Mon Jun 19, 2006 6:31 pm
I don't know if this is the problem, but I would use a different variable name for each loop (instead of x both times use a and b)
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Jun 19, 2006 6:40 pm
yah, i tried that too, i updated it to:
Code: Select all
$sql2 = "SELECT * FROM var_sections WHERE Section_AID = $sectionNID ORDER BY Section_Weight ASC";
$result = mysql_query($sql2) or die (mysql_error());
thanks though
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Thu Jun 22, 2006 9:38 pm
i've still bee unable to solve this riddle.
why would a loop that is closing not allow a parent loop to continue? anyone?
tecktalkcm0391
DevNet Resident
Posts: 1030 Joined: Fri May 26, 2006 9:25 am
Location: Florida
Post
by tecktalkcm0391 » Thu Jun 22, 2006 10:07 pm
Try:
Code: Select all
echo "<div id='dhtmlgoodies_slidedown_menu'><ul>" ;
// Begin PHP Loop #1 - Works ------->
$sql = "SELECT COUNT(*) FROM var_section_names";
$numrecord = mysql_query($sql);
$numrecords = mysql_fetch_array($numrecord);
$numrecords[0];
$intRecsPerPage=12;
if($_POST["intpage"]=="")
{
$intpage=1;
}
$sql = "SELECT * FROM var_section_names ORDER BY Section_N_Weight ASC";
$result = mysql_query($sql) or die (mysql_error());
for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
{
if($x >= $numrecords[0])
{
break;
}
$sectionresults = mysql_fetch_array($result);
$sectionName = $sectionresults["Section_N_Name"];
$sectionNID = $sectionresults["Section_N_ID"];
echo "<li><a href='#'>$sectionName</a>";
echo "<ul>";
// Begin Static Loop - Works -------> http://www.thevariables.com/_/
echo "<li><a href'#'>Roll Out 1</a></li><li><a href'#'>Roll Out 1</a></li>";
// End Static Loop - Works ------->
// Begin PHP Loop #2 - Doesn't Work -------> http://www.thevariables.com/_/indexBad.php
$sql2 = "SELECT COUNT(*) FROM var_sections WHERE Section_AID = '$sectionNID'";
$numrecord = mysql_query($sql2);
$numrecords = mysql_fetch_array($numrecord);
$numrecords[0];
$intRecsPerPage=12;
if($_POST["intpage"]=="")
{
$intpage=1;
}
$sql2 = "SELECT * FROM var_sections WHERE Section_AID = '{$sectionNID}' ORDER BY Section_Weight ASC";
$result = mysql_query($sql2) or die (mysql_error());
for($y = (($intpage-1) * $intRecsPerPage); $y < ((($intpage-1) * $intRecsPerPage) + $intRecsPerPage); $y++)
{
if($y >= $numrecords[0])
{
break;
}
$sectionsresults = mysql_fetch_array($result);
$sectionsPT = $sectionsresults["Section_PT"];
$sectionsID = $sectionsresults["Section_ID"];
echo "<li><a href='#'>$sectionsPT</a></li>";
}
echo "</ul>";
// End PHP Loop #2 - Doesn't Work------->
echo "</li>";
}
// End PHP Loop #1 - Works ------->
echo "</ul>";
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Tue Jul 04, 2006 10:31 am
hmm... nope, this doesn't work either...
you'd think that something could loop inside of something without so much trouble.