taydag
01-27-2004, 08:31 AM
Hi ppl
i would like to display my categories in my menu , but i got some conditions , for example ;
MAINCAT1 subcat1a subcat1b subcat1c
MAINCAT2 subcat2a subcat2b subcat2c
MAINCAT3 subcat3a subcat3b subcat3c
....
i would like to display thEsE categories like this (when MAINCAT1 link or one of its sub categories link is active )
MAINCAT1
subcat1a
subcat1b
subcat1c
MAINCAT2
MAINCAT3
MAINCAT4
....
OR (when MAINCAT3 or one of its sub categories is active seemed on the page)
MAINCAT1
MAINCAT2
MAINCAT3
subcat3a
subcat3b
subcat3c
MAINCAT4
i have try to organize 2 while loops inside of each other but nothing successfull.
plesa check the code i wrote at the bottom of the page ...
also my structure of my database where categories take place is like
CATEGORY TOPCATEGORY
MAINCAT1 0
MAINCAT2 0 (all main cats hae "o" value in topcategory column)
MAINCAT3 0
subcat1a MAINCAT1
subcat1b MAINCAT1
subcat1c MAINCAT1
subcat2a MAINCAT2
subcat2b MAINCAT2
subcat2c MAINCAT2
so on ......
thanks by now for your valuable helps by now.
<? function category_list () {
global $req_topcategory, $kategori, $sql_req, $req_category, $result3, $sql3, $adult, $categoryname1, $categorydesc, $categoryid, $topcategory, $conn ;
// kategoriyi kontorol edelim
$sql1 = "SELECT * FROM category WHERE topcategory = '0'" ;
print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
print "<tr>\n";
print "<td bgcolor=\"#0076A3\"><div align=\"center\"><strong><font color=\"#FFFFFF\">CATEGORIES</font></strong></div></td>\n";
print "</tr>\n";
$result1 = mysql_query($sql1, $conn) or die(mysql_error());
while ($na1 = mysql_fetch_array($result1)) {
$category = $na1['category'];
$categorydesc = $na1['categorydesc'];
print "<tr>";
print " <td width=\"100%\"><font size=\"2\" face=\"verdana\"><div align=\"left\"><a href=\"category.php?name=$category\"><b>$categorydesc </b> </a>(<font color=\"red\"> </font>)</div></font></td>";
print "</td>";
print "</tr>\n";
$_GET['name'] = $req_category;
$sql_req = "SELECT * FROM category WHERE category = '".$req_category."' ";
$result_req = mysql_query($sql_req, $conn) or die(mysql_error());
$na_req = mysql_fetch_array($result_req);
$req_topcategory = $na_req['topcategory'];
switch($req_topcategory){
case '0' ;
$sql2 = "SELECT * FROM category WHERE topcategory = '".$req_category."'" ;
break;
default ;
$sql2 = "SELECT * FROM category WHERE topcategory = '".$req_topcategory."'" ;
}
$result2 = mysql_query($sql2, $conn) or die(mysql_error());
while ($na2 = mysql_fetch_array($result2)) {
$category2 = $na2['category'];
$categorydesc2 = $na2['categorydesc'];
print "<tr>";
print " <td width=\"100%\"><font size=\"2\" face=\"verdana\"><div align=\"left\"><a href=\"category.php?name=$category2\">$categorydesc2 </a>(<font color=\"red\"> </font>)</div></font></td>";
print "</td>";
} }
print "</table>";
}
?>
i would like to display my categories in my menu , but i got some conditions , for example ;
MAINCAT1 subcat1a subcat1b subcat1c
MAINCAT2 subcat2a subcat2b subcat2c
MAINCAT3 subcat3a subcat3b subcat3c
....
i would like to display thEsE categories like this (when MAINCAT1 link or one of its sub categories link is active )
MAINCAT1
subcat1a
subcat1b
subcat1c
MAINCAT2
MAINCAT3
MAINCAT4
....
OR (when MAINCAT3 or one of its sub categories is active seemed on the page)
MAINCAT1
MAINCAT2
MAINCAT3
subcat3a
subcat3b
subcat3c
MAINCAT4
i have try to organize 2 while loops inside of each other but nothing successfull.
plesa check the code i wrote at the bottom of the page ...
also my structure of my database where categories take place is like
CATEGORY TOPCATEGORY
MAINCAT1 0
MAINCAT2 0 (all main cats hae "o" value in topcategory column)
MAINCAT3 0
subcat1a MAINCAT1
subcat1b MAINCAT1
subcat1c MAINCAT1
subcat2a MAINCAT2
subcat2b MAINCAT2
subcat2c MAINCAT2
so on ......
thanks by now for your valuable helps by now.
<? function category_list () {
global $req_topcategory, $kategori, $sql_req, $req_category, $result3, $sql3, $adult, $categoryname1, $categorydesc, $categoryid, $topcategory, $conn ;
// kategoriyi kontorol edelim
$sql1 = "SELECT * FROM category WHERE topcategory = '0'" ;
print "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
print "<tr>\n";
print "<td bgcolor=\"#0076A3\"><div align=\"center\"><strong><font color=\"#FFFFFF\">CATEGORIES</font></strong></div></td>\n";
print "</tr>\n";
$result1 = mysql_query($sql1, $conn) or die(mysql_error());
while ($na1 = mysql_fetch_array($result1)) {
$category = $na1['category'];
$categorydesc = $na1['categorydesc'];
print "<tr>";
print " <td width=\"100%\"><font size=\"2\" face=\"verdana\"><div align=\"left\"><a href=\"category.php?name=$category\"><b>$categorydesc </b> </a>(<font color=\"red\"> </font>)</div></font></td>";
print "</td>";
print "</tr>\n";
$_GET['name'] = $req_category;
$sql_req = "SELECT * FROM category WHERE category = '".$req_category."' ";
$result_req = mysql_query($sql_req, $conn) or die(mysql_error());
$na_req = mysql_fetch_array($result_req);
$req_topcategory = $na_req['topcategory'];
switch($req_topcategory){
case '0' ;
$sql2 = "SELECT * FROM category WHERE topcategory = '".$req_category."'" ;
break;
default ;
$sql2 = "SELECT * FROM category WHERE topcategory = '".$req_topcategory."'" ;
}
$result2 = mysql_query($sql2, $conn) or die(mysql_error());
while ($na2 = mysql_fetch_array($result2)) {
$category2 = $na2['category'];
$categorydesc2 = $na2['categorydesc'];
print "<tr>";
print " <td width=\"100%\"><font size=\"2\" face=\"verdana\"><div align=\"left\"><a href=\"category.php?name=$category2\">$categorydesc2 </a>(<font color=\"red\"> </font>)</div></font></td>";
print "</td>";
} }
print "</table>";
}
?>