/    Sign up×
Community /Pin to ProfileBookmark

php/mysql menu

[COLOR=Navy] <?

$first_time=true;
$sql=$obj_db->query(“select * from categories where par_id=’0′”);
while ($rs_sql=$obj_db->fetch_array($sql)) {
echo “<tr><td class=’nav-td’><img src='”.THEME.”bullet.gif’> <a href='”.LINK.”category&amp;cid=”.$rs_sql[‘id’].”‘ class=’nav-left’>”.$rs_sql[‘cat_name’].”</a></td></tr>”;

$cid=”;
if( isset($_GET[‘cid’]) ) {
$cid=$_GET[‘cid’];
$q=$obj_db->query(“select * from categories where par_id=’$cid'”);
while ($rs_q=$obj_db->fetch_array($q)) {
if($first_time) {
echo “<tr><td class=’nav-sub-td’>&bull; <a href='”.LINK.”products&amp;cid=”.$cid.”&amp;sid=”.$rs_q[‘id’].”‘ class=’nav-sub-left’>”.$rs_q[‘cat_name’].”</a></td></tr>”;
}
}
$first_time=false;
}
}
?>[/COLOR]

what’s wrong with this code

it work’s all well for only 1 main-category and it’s sub categories
but if there i add 2nd category and subcategories of 2nd main category,
the sub-categories of 2nd main category also shows under the 1st main category

i just want to show the sub-categories under the relative main category

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sb_Nov 17.2006 — <i>
</i>a href='".LINK."

That doesn't look kosher. Make it easy, just start with displaying the link and all that without the other fancy "material." It seems like you are going about this in a wierd way. If I may suggest I would try using two databases.

<i>
</i>Main Category DB (CDB)
-CID
-Name


<i>
</i>Sub Category DB (SCDB)
-SCID
-CID
-Name
-Link


<i>
</i>SELECT * FROM <span><code>CDB</code></span>
Loop through each row
Display Main Category Header
SELECT * FROM <span><code>SCDB</code></span> WHERE <span><code>CID</code></span> = '$row['CID']'
Loop through each row
Display Sub Category Header
Copy linkTweet thisAlerts:
@mahfoozauthorNov 17.2006 — ok

it seems that u just display all the CDB and SCDB on the same page

but i dispaly CDB in 1st page while SCDB on 2nd page based on the [B][COLOR=Navy]$_GET[''][/COLOR][/B] method

and show sub categories under the relative category
×

Success!

Help @mahfooz 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 5.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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