Hey,
Ok I am stating to confuse myself with a query that I am trying to simplify. Basically I have two tables - one I call cluster and one I call events. The cluster is basically holding information on the "venue" for the event. It has the following fields:
fld_id
fld_name
Now, the table events holds the following information:
fld_id
fld_name
fld_cluster
So, what I wanted to do was this:
// start of query
$sql = "SELECT
cluster.fld_id AS cluster_id,
cluster.fld_name AS cluster_name
COUNT(events.fld_id) AS numevents
FROM tbl_events_clusters AS cluster, tbl_events AS events
WHERE cluster.fld_id = '5124'
GROUP BY cluster.fld_id";
// execute query
$result = mysql_query($sql) or die ("Error in query: $sql. " .mysql_error());
// get array
$row = mysql_fetch_array($result);
echo $row['cluster_name'];
// events found
if ($row['numevents'] > 0) {
echo "This cluster has events associated to it.";
}
Now, basically the main problem is with the numevents variable - I want to show that message if the cluster has events associated to it, and not show it if it does not.
The code above shows this message regardless of whether or not the cluster has events associated to it.
When I echoed the numevent variable it counted the entire list of events, not just the ones associated to the cluster.
I thought the WHERE statement would do this?
I was thinking I needed to use a JOIN somewhere perhaps, but I'm finding them confusing to think about to be honest.
Any ideas?
Cheers,
Chris