/    Sign up×
Community /Pin to ProfileBookmark

I have a menu on my site which is built from php using categories in the database.

What i’m trying to do is when a menu item is clicked it displays the sub category choices benath it.

[CODE]
<div class=”mainMenu”>
<table width=”80%” border=”0″>
<tr>
<th>Menu</th>
</tr>
<?php do { ?>
<table width=”80%” border=”0″>
<tr>
<td><a href=”products.php?category=<?php echo $row_rsMenu[‘category’]; ?>”><?php echo $row_rsMenu[‘category’]; ?></a></td>

</tr>
</table>
<?php } while ($row_rsMenu = mysql_fetch_assoc($rsMenu)); ?>
</table>
</div>
[/CODE]

thats the code for the menu as it is now. i tried putting another do in there so while its same category it displays sub category but it didn’t work.

so for instance it would look like:

CLOTHING
tees
jeans
socks
ACCESSORIES
belts
bags
hats

i’ve created a new recordset called rsSubMenu which brings in the sub categories. Any help or pointers to tutorial that may help?

Cheers

Sean

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@sean1983ukauthorFeb 21.2007 — I tried this:

[CODE]
<div class="mainMenu">
<table width="80%" border="0">
<tr>
<th>Menu</th>
</tr>
<?php do { ?>
<table width="80%" border="0">
<tr>
<td><a href="products.php?category=<?php echo $row_rsMenu['category']; ?>"><?php echo $row_rsMenu['category']; ?></a></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?sub category=<?php echo $row_rsSubMenu['sub category']; ?>"><?php echo $row_rsSubMenu['sub category']; ?></a></td>
</tr>
<?php } while ($row_rsSubMenu = mysql_fetch_assoc($rsSubMenu)); ?>
</table>
<?php } while ($row_rsMenu = mysql_fetch_assoc($rsMenu)); ?>
</table>
</div>
[/CODE]


but this displays it like:

MAIN CATEGORY

sub category

sub category

sub category

sub category

sub category

sub category

sub category

sub category

MAIN CATEGORY

MAIN CATEGORY

MAIN CATEGORY


so its displaying all the sub categories under just the first main category..

any help?
Copy linkTweet thisAlerts:
@darkninjaFeb 22.2007 — [CODE]

<?php while ($row_rsMenu = mysql_fetch_assoc($rsMenu)) {

echo <<<ABC
<table width="80%" border="0">
<tr>
<td><a href="products.php?category=$row_rsMenu['category']">$row_rsMenu['category']</a></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?sub category=$row_rsSubMenu['sub category']">$row_rsSubMenu['sub category']</a></td>
</tr>
</table>
ABC;

}
[/CODE]


Tried that?
Copy linkTweet thisAlerts:
@sean1983ukauthorFeb 22.2007 — [CODE]

<?php while ($row_rsMenu = mysql_fetch_assoc($rsMenu)) {

echo <<<ABC
<table width="80%" border="0">
<tr>
<td><a href="products.php?category=$row_rsMenu['category']">$row_rsMenu['category']</a></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?sub category=$row_rsSubMenu['sub category']">$row_rsSubMenu['sub category']</a></td>
</tr>
</table>
ABC;

}
[/CODE]


Tried that?[/QUOTE]




Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:Apache2Webslearning_phptest.php on line 27
Copy linkTweet thisAlerts:
@darkninjaFeb 22.2007 — [CODE]
<?php while ($row_rsMenu = mysql_fetch_assoc($rsMenu)) {

echo <<<ABC
<table width="80%" border="0">
<tr>
<td><a href="products.php?category=$row_rsMenu[category]">$row_rsMenu[category]</a></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?sub category=$row_rsSubMenu[sub category]">$row_rsSubMenu[sub category]</a></td>
</tr>
</table>
ABC;
[/CODE]


oops, just had to remove the single quotes.
Copy linkTweet thisAlerts:
@sean1983ukauthorFeb 22.2007 — [CODE]
<?php while ($row_rsMenu = mysql_fetch_assoc($rsMenu)) {

echo <<<ABC
<table width="80%" border="0">
<tr>
<td><a href="products.php?category=$row_rsMenu[category]">$row_rsMenu[category]</a></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?sub category=$row_rsSubMenu[sub category]">$row_rsSubMenu[sub category]</a></td>
</tr>
</table>
ABC;
[/CODE]


oops, just had to remove the single quotes.[/QUOTE]


hey ?

its still saying:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in C:Apache2Webslearning_phptest.php on line 31
Copy linkTweet thisAlerts:
@darkninjaFeb 23.2007 — $row_rsSubMenu[sub category]

Theres a space there, get rid of it
Copy linkTweet thisAlerts:
@sean1983ukauthorFeb 24.2007 — $row_rsSubMenu[sub category]

Theres a space there, get rid of it[/QUOTE]


have tried:

[CODE]
<?php while ($row_rsMenu = mysql_fetch_assoc($rsMenu)) {

echo <<<ABC
<table width="80%" border="0">
<tr>
<td><a href="products.php?category=$row_rsMenu[category]">$row_rsMenu[category]</a></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?subCategory=$row_rsSubMenu[subCategory]">$row_rsSubMenu[subCategory]</a></td>
</tr>
</table>
ABC;
[/CODE]


but get the error:

Parse error: parse error, unexpected '<' in C:Apache2Webslearning_phptest.php on line 37
Copy linkTweet thisAlerts:
@sean1983ukauthorFeb 24.2007 — I've got it to display this now:

Accessories

bags

Clothing

bags

Jewellery

bags


using the following code:

[CODE]
<div class="mainMenu">
<table width="80%" border="0">
<tr>
<th>Menu</th>
</tr>
<?php do { ?>
<table width="80%" border="0">
<tr>
<td><?php echo $row_rsCategories['category']; ?></td>
</tr>
<?php do { ?>
<tr>
<td><a href="products.php?sub category=<?php echo $row_rsSubMenu['subCategory']; ?>"><?php echo $row_rsSubMenu['subCategory']; ?></a></td>
</tr>
<?php } while (rsSubMenu.category == rsCategories.category); ?>
</table>
<?php } while ($row_rsCategories = mysql_fetch_assoc($rsCategories)); ?>
</table>
</div>
[/CODE]


but as you can see its only displaying one sub category and using the same one for each main category
Copy linkTweet thisAlerts:
@darkninjaFeb 24.2007 — that would probably depend on your SQL query, wanna post it here?
×

Success!

Help @sean1983uk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...