Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display total subcategories!!

Status
Not open for further replies.

willya340

Technical User
Jul 2, 2001
17
KW
Hi

I`ve searched everywhere for this but couldn`t find it.

I`m using Dreamweaver MX with PHP/MySQL and 1 database holding the following tables:

tipcat table
tipcatid
tipcat

tipsubcat
tipsubcatid
tipsubcat
tipcatid

both are joind with "tipcatid" field.

I got so far of displaying the categories , and now i would like to display the total number of subcatogeries for each category like this:

Category1 (Total 4 subcats)
Category2 (Total 2 subcats)
and so on.

Its like when you look at shopping sites where they show you the products and in brackets they have the total number of the subproducts this product category has.

I hope I was clear with my question.
To elaborate on what i want , here is and example from yahoo directory if you look at the category listing they have the category name and the total subcats in () , for example "Directories (303)"

now how do i do that.
Thanks

at the moment i got so far (this code is created with dwmx)



PHP:--------------------------------------------------------------------------------
<?php require_once('../../Connections/connKAC.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = &quot;&quot;, $theNotDefinedValue = &quot;&quot;)
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case &quot;text&quot;:
$theValue = ($theValue != &quot;&quot;) ? &quot;'&quot; . $theValue . &quot;'&quot; : &quot;NULL&quot;;
break;
case &quot;long&quot;:
case &quot;int&quot;:
$theValue = ($theValue != &quot;&quot;) ? intval($theValue) : &quot;NULL&quot;;
break;
case &quot;double&quot;:
$theValue = ($theValue != &quot;&quot;) ? &quot;'&quot; . doubleval($theValue) . &quot;'&quot; : &quot;NULL&quot;;
break;
case &quot;date&quot;:
$theValue = ($theValue != &quot;&quot;) ? &quot;'&quot; . date(&quot;Y-m-d&quot;,strtotime($theValue)) . &quot;'&quot; : &quot;NULL&quot;;
break;
case &quot;defined&quot;:
$theValue = ($theValue != &quot;&quot;) ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= &quot;?&quot; . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS[&quot;MM_insert&quot;])) && ($HTTP_POST_VARS[&quot;MM_insert&quot;] == &quot;form1&quot;)) {
$insertSQL = sprintf(&quot;INSERT INTO tipcat (tipcat) VALUES (%s)&quot;,
GetSQLValueString($HTTP_POST_VARS['tipcat'], &quot;text&quot;));

mysql_select_db($database_connKAC, $connKAC);
$Result1 = mysql_query($insertSQL, $connKAC) or die(mysql_error());

$insertGoTo = &quot;index.php&quot;;
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? &quot;&&quot; : &quot;?&quot;;
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf(&quot;Location: %s&quot;, $insertGoTo));
}

mysql_select_db($database_connKAC, $connKAC);
$query_rscats = &quot;SELECT * FROM tipcat ORDER BY tipcat.tipcat&quot;;
$rscats = mysql_query($query_rscats, $connKAC) or die(mysql_error());
$row_rscats = mysql_fetch_assoc($rscats);
$totalRows_rscats = mysql_num_rows($rscats);

mysql_select_db($database_connKAC, $connKAC);
$query_rssubcatcount = &quot;SELECT COUNT(DISTINCT tipsubcat.tipsubcat) AS subcount FROM tipcat, tipsubcat WHERE tipcat.tipcatid = tipsubcat.tipcatid GROUP BY tipcat&quot;;
$rssubcatcount = mysql_query($query_rssubcatcount, $connKAC) or die(mysql_error());
$row_rssubcatcount = mysql_fetch_assoc($rssubcatcount);
$totalRows_rssubcatcount = mysql_num_rows($rssubcatcount);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td><table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<th>Categories</th>
</tr>
<tr>
<td><table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<?php do { ?>
<tr>
<td><?php echo $row_rscats['tipcat']; ?></td>
<td><?php echo $row_rssubcatcount['subcount']; ?> Subcats</td>
<td><a href=&quot;cat_update.php?catid=<?php echo $row_rscats['tipcatid']; ?>&quot;>Edit</a></td>
<td><a href=&quot;subcat_add.php?catid=<?php echo $row_rscats['tipcatid']; ?>&quot;>Addsubcats</a></td>
</tr>
<?php } while ($row_rscats = mysql_fetch_assoc($rscats)); ?>
</table></td>
</tr>
</table></td>
<td> 
<form method=&quot;post&quot; name=&quot;form1&quot; action=&quot;<?php echo $editFormAction; ?>&quot;>
<table align=&quot;center&quot;>
<tr valign=&quot;baseline&quot;>
<td nowrap align=&quot;right&quot;>Tipcat:</td>
<td><input type=&quot;text&quot; name=&quot;tipcat&quot; value=&quot;&quot; size=&quot;32&quot;>
</td>
</tr>
<tr valign=&quot;baseline&quot;>
<td nowrap align=&quot;right&quot;> </td>
<td><input type=&quot;submit&quot; value=&quot;Insert Record&quot;>
</td>
</tr>
</table>
<input type=&quot;hidden&quot; name=&quot;MM_insert&quot; value=&quot;form1&quot;>
</form>
<p> </p></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rscats);

mysql_free_result($rssubcatcount);
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top