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 = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO tipcat (tipcat) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['tipcat'], "text");
mysql_select_db($database_connKAC, $connKAC);
$Result1 = mysql_query($insertSQL, $connKAC) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_connKAC, $connKAC);
$query_rscats = "SELECT * FROM tipcat ORDER BY tipcat.tipcat";
$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 = "SELECT COUNT(DISTINCT tipsubcat.tipsubcat) AS subcount FROM tipcat, tipsubcat WHERE tipcat.tipcatid = tipsubcat.tipcatid GROUP BY tipcat";
$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="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Categories</th>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td><?php echo $row_rscats['tipcat']; ?></td>
<td><?php echo $row_rssubcatcount['subcount']; ?> Subcats</td>
<td><a href="cat_update.php?catid=<?php echo $row_rscats['tipcatid']; ?>">Edit</a></td>
<td><a href="subcat_add.php?catid=<?php echo $row_rscats['tipcatid']; ?>">Addsubcats</a></td>
</tr>
<?php } while ($row_rscats = mysql_fetch_assoc($rscats)); ?>
</table></td>
</tr>
</table></td>
<td>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Tipcat:</td>
<td><input type="text" name="tipcat" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert Record">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rscats);
mysql_free_result($rssubcatcount);
?>
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 = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "" ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "" ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "" ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "" ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "" ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO tipcat (tipcat) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['tipcat'], "text");
mysql_select_db($database_connKAC, $connKAC);
$Result1 = mysql_query($insertSQL, $connKAC) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_connKAC, $connKAC);
$query_rscats = "SELECT * FROM tipcat ORDER BY tipcat.tipcat";
$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 = "SELECT COUNT(DISTINCT tipsubcat.tipsubcat) AS subcount FROM tipcat, tipsubcat WHERE tipcat.tipcatid = tipsubcat.tipcatid GROUP BY tipcat";
$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="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th>Categories</th>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<?php do { ?>
<tr>
<td><?php echo $row_rscats['tipcat']; ?></td>
<td><?php echo $row_rssubcatcount['subcount']; ?> Subcats</td>
<td><a href="cat_update.php?catid=<?php echo $row_rscats['tipcatid']; ?>">Edit</a></td>
<td><a href="subcat_add.php?catid=<?php echo $row_rscats['tipcatid']; ?>">Addsubcats</a></td>
</tr>
<?php } while ($row_rscats = mysql_fetch_assoc($rscats)); ?>
</table></td>
</tr>
</table></td>
<td>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Tipcat:</td>
<td><input type="text" name="tipcat" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Insert Record">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($rscats);
mysql_free_result($rssubcatcount);
?>