Jump to content

subcat problem can anyone help?


raven2009

Recommended Posts

hi all

ive been learning php doing well so far until... i come to the subcategories

 

right what i aim to do is that the left pannel displays the maincat then if a user clicks on a main cat that has a subcat then the cat menu expands to enclude both, heres my code below to see where ive gone wrong any help will be much appriciated :o)

 

 

 

<?php

$categories="select * from categories where parent='0' order by id";

$listCats=mysql_query($categories);

 

while($row=mysql_fetch_array($listCats))

{

 

?>

<tr>

<td height="15" bgcolor="#006699"><h5><img src="Images/arrwo_4.png" alt="" width="10" height="7" /></h5></td>

<td bgcolor="#006699"><h5><a href="storesinfo.php?s=<?php echo $row['id']; ?>" class="White"><font color=""><?php echo $row['category']; ?></font></a></h5></td>

</tr>

<?php

$parId=$row['id'];

$childCategories="select * from categories where parent='$parId' order by id";

$listChildCategories=mysql_query($childCategories);

while($rowC=mysql_fetch_array($listChildCategories))

{

?>

<tr>

<td height="15" bgcolor="#009900"><h5> </h5></td>

<td bgcolor="#009900"><h5><a href="storesinfo.php?s=<?php echo $rowC['id']; ?>" class="White"><font color=""><?php echo $rowC['category']; ?></font></a></h5></td>

</tr>

<?

}

 

}

?>

<?php

if(isset($_GET['p']))

{

$p=$_GET['p'];

$categories="select * from categories where parent='$p'";

}

else

{

$categories="select * from categories";

}

$listCats=mysql_query($categories);

 

while($row=mysql_fetch_array($listCats))

{

 

?>

<?php

Link to comment
https://forums.phpfreaks.com/topic/152969-subcat-problem-can-anyone-help/
Share on other sites

sorry, dunno if this is right but he it goes

 

<?php
$categories="select * from categories where parent='0' order by id";
$listCats=mysql_query($categories);	

while($row=mysql_fetch_array($listCats))
{

?>
                                    <tr>
                                      <td height="15" bgcolor="#006699"><h5><img src="Images/arrwo_4.png" alt="" width="10" height="7" /></h5></td>
                                      <td bgcolor="#006699"><h5><a href="storesinfo.php?s=<?php echo $row['id']; ?>" class="White"><font color=""><?php echo $row['category']; ?></font></a></h5></td>
                                    </tr>
                                    <?php
$parId=$row['id'];				
	$childCategories="select * from categories where parent='$parId' order by id";
$listChildCategories=mysql_query($childCategories);	
	while($rowC=mysql_fetch_array($listChildCategories))
{	
?>
                                    <tr>
                                      <td height="15" bgcolor="#009900"><h5> </h5></td>
                                      <td bgcolor="#009900"><h5><a href="storesinfo.php?s=<?php echo $rowC['id']; ?>" class="White"><font color=""><?php echo $rowC['category']; ?></font></a></h5></td>
                                    </tr>
                                    <?
}

}
?>
                                    <?php
if(isset($_GET['p']))	
{
$p=$_GET['p'];
$categories="select * from categories where parent='$p'";
}
else
{
$categories="select * from categories";
}
$listCats=mysql_query($categories);	

while($row=mysql_fetch_array($listCats))
{

?>
                                    <?php
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.