Hey guys.
First of all, its been 2 days, and already 2:30am in the morning. I've eaten a steel fork, jumped over the moon, broke an arm, and cant get it to work. Will somebody please assist me in this;
The end result sound simple, and maybe it is, but I dont get it.
Okay, let me start.
I am building a small site, where local people can post ads in categories. Example :
LOCATION
--City One (2)
--City Two (4)
-- City Three (7)
Dwelling Type
--Townhouse (1)
--Estate (4)
--Land (8)
Now the only thing that I need to achieve, is to count and echo the total of SQL entries in each sub category, next to each location.
I am using about 4 SQL table,s but here is the important ones. I've joint these tables in all possible ways, and tried everything.
CREATE TABLE IF NOT EXISTS `item` (
`itemID` int(11) NOT NULL AUTO_INCREMENT,
`adID` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`CreationDate` date NOT NULL,
`Expiration` date NOT NULL,
`Views` int(11) NOT NULL DEFAULT '1',
`Responses` int(11) NOT NULL DEFAULT '0',
`UserEmail` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`IP` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`Title` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`Promote` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'None',
`catID` int(11) NOT NULL DEFAULT '0',
`SEO` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`Description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`itemID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;
INSERT INTO `item` (`itemID`, `adID`, `CreationDate`, `Expiration`, `Views`, `Responses`, `UserEmail`, `IP`, `Title`, `Promote`, `catID`, `SEO`, `Description`) VALUES
(6, '20100406192824830999764294722976', '2010-05-10', '2010-07-25', 1, 1, 'vanwykfj@gmail.com', '::1', 'Big home to let', 'None', 1, 'big-home-to-let', 'this is a big home to let in, lets say, new york, cause you wont recognise my small-town towns here'),
(7, '20100406192916499097777902080358', '2010-05-10', '2010-07-25', 1, 1, 'vanwykfj@gmail.com', '::1', 'Medium home to let', 'None', 1, 'medium-home-to-let', 'this is a medium home to let in, lets say, Chicago'),
(5, '20100406192731929426053392405412', '2010-05-10', '2010-07-25', 1, 1, 'vanwykfj@gmail.com', '::1', 'Small home to let', 'None', 1, 'small-home-to-let', 'this is a small home to let');
CREATE TABLE IF NOT EXISTS `itemfield` (
`fID` int(11) NOT NULL AUTO_INCREMENT,
`adID` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`fieldID` int(11) NOT NULL DEFAULT '1',
`FieldValue` varchar(250) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
`catID` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`fID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=22 ;
INSERT INTO `itemfield` (`fID`, `adID`, `fieldID`, `FieldValue`, `catID`) VALUES
(20, '20100406192916499097777902080358', 1, '3', 1),
(19, '20100406192916499097777902080358', 2, '2', 1),
(18, '20100406192824830999764294722976', 8, 'New York', 1),
(17, '20100406192824830999764294722976', 1, '2', 1),
(16, '20100406192824830999764294722976', 2, '1', 1),
(15, '20100406192731929426053392405412', 8, 'New York', 1),
(14, '20100406192731929426053392405412', 1, '2', 1),
(13, '20100406192731929426053392405412', 2, '1', 1),
(21, '20100406192916499097777902080358', 8, 'Chicago', 1);
--> I'm trying to keep it short!!! Almost done.... So here is the current code - well, one of the many tries - that I tried.
<?php require_once('../Connections/classi.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="common.css" rel="stylesheet" type="text/css" />
<?php
mysql_select_db($database_classi, $classi);
$query_filters = "SELECT Title FROM filter WHERE catID = '".$_GET['catID']."' ORDER BY Title DESC";
$filters = mysql_query($query_filters, $classi) or die(mysql_error());
$row_filters = mysql_fetch_assoc($filters);
$totalRows_filters = mysql_num_rows($filters);
?>
</head>
<body>
<table width="270" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div class="filter_top">Your total ads found</div></td>
</tr>
<?php
do { ?>
<tr>
<td><div class="filter_title"><?php echo $row_filters['Title']; ?></div></td>
</tr>
<tr>
<td><div class="filter_subtitle">
<?php
$query_subfilters = "SELECT * FROM filter WHERE Title = '".$row_filters['Title']."' ORDER BY Title DESC";
$subfilters = mysql_query($query_subfilters, $classi) or die(mysql_error());
$row_subfilters = mysql_fetch_assoc($subfilters);
$totalRows_subfilters = mysql_num_rows($subfilters);
?>
<?php
$arr = explode(",", $row_subfilters['Values']);
reset($arr);
foreach ($arr as $line)
{
mysql_select_db($database_classi, $classi);
$query_countitems = "SELECT fID FROM itemfield WHERE FieldValue = '$line' AND catID = '".$_GET['catID']."'";
$countitems = mysql_query($query_countitems, $classi) or die(mysql_error());
$totalRows_countitems = mysql_num_rows($countitems);
echo $line.' ('.$totalRows_countitems.')<br>'; }
?>
</div></td>
</tr>
<tr>
<td><div class="filter_hr"></div></td>
</tr>
<?php } while ($row_filters = mysql_fetch_assoc($filters)); ?>
<tr>
<td><div class="filter_bottom"></div></td>
</tr>
</table>
</body>
</html>
#########################################
I will so appreciate anybody's help
:-/
ps: after lots and lots of gazzillions tries - i thought i got it to work - but only the first entry/location's total entries displays. and, i guess there might be a better, more improved and easier way?
thanx guys