Steven Dowd
|
Posted: 10/09/2002, 2:21 AM |
|
Can anyone help me modify the tree form so that it shows a count() of the
items in the directories as part of the actual tree menu?
I have a std db' named , Classifieds tree, in php4+mysql db, I have grabbed
the produced code below to show that all is basically std, but itisnt set to
use custom code in the project.
In my Project this tree form is linked in CC to an "ads_categories" mysql
table, my classifieds are in an "ads_listings" table
How do i introduce a mysql count for how many I would think i need something
like this
"select count(*) from ads_listings where ad_id=$category_id" ?
Thanks
Steven
//-------------------------------
?>
<table >
<tr>
<td bgcolor="#F99E39" align="center">
<font face="arial" color="#000000" style="font-weight:
bold"><?=$sFormTitle?></font>
</td>
</tr>
<tr>
<td bgcolor="#FFBB77">
<nobr><font face="arial" size="2" style="font-weight: bold">
<a href="<?= $action_page ?>?FormName=Tree">
<font face="arial" size="2" style="font-weight: bold">Top</font></a>
<?
$sSQL = "select category_id, category_name, category_id_parent from
ads_categories";
$sCatID = get_param("category_id");
if(!strlen($sCatID) || !is_number($sCatID))
{
//-------------------------------
// Root category
//-------------------------------
$sWhere = " WHERE category_id_parent IS NULL OR category_id_parent=0";
}
else
{
//-------------------------------
// Subcategory
//-------------------------------
$sWhere = " where category_id=" . $sCatID;
$db->query($sSQL . $sWhere);
$db->next_record();
$current_category = tohtml($db->f("category_name"));
$sParCatID = tohtml($db->f("category_id_parent"));
//-------------------------------
// Build Path
//-------------------------------
$sPath = "";
while($sParCatID != "")
{
$db->query($sSQL . " where category_id=" . $sParCatID);
if($db->next_record())
{
$category_name = tohtml($db->f("category_name"));
$category_id = tohtml($db->f("category_id"));
$sParCatID = tohtml($db->f("category_id_parent"));
$sPath="<a
href=\"$action_page?FormName=Tree&category_id=$category_id\">
<font " . "face=\"arial\" size=\"2\"
style=\"font-weight: bold\"" . ">" . $category_name . "</font></a> > " .
$sPath;
}
else
break;
}
echo " > ".$sPath;
echo $current_category;
$sWhere = " where category_id_parent=" . $sCatID;
}
?>
</font></nobr>
</td>
</tr>
<?
//-------------------------------
// Categories list
//-------------------------------
$db->query($sSQL . $sWhere);
if($db->next_record())
{
//-------------------------------
// Print subcategories
//-------------------------------
do
{
$category_id = tohtml($db->f("category_id"));
$category_name = tohtml($db->f("category_name"));
?>
<tr>
<td bgcolor="#FFFFFF">
<a href="<?= $action_page ?>?FormName=Tree&category_id=<?=
$category_id ?>"><font face="arial" size="2"><?= $category_name
?></font></a></td></tr>
<?
} while ($db->next_record());
}
//-------------------------------
echo "</table>";
//-------------------------------
|
|
|
Chris Seymour
|
Posted: 10/11/2002, 10:06 AM |
|
Hi Steven,
I used the following bit of code in an ASP app I did.
I put this in the Custom Show event of the Tree form:
SetVar "Category", GetValueHTML(rs,"name") & " (" & dlookup("ads",
"count(*)","category_id = " & GetValue(rs,"category_id")) & " ads)"
Let me know if you want some help translating it to PHP.
Cheers.
Chris
|
|
|
|