Okies,
So, I'm working on my show database, and I've got the basics of MySql figured out to get done what I need to get done...
What I'm attempting to do right now I know I can do with a different MySQL query and some PHP manipulation of the results, but I just know there's a MySQL command that can do what I want in a single line of code..
Here's my current MySQL request..
SELECT DISTINCT pn_showstate FROM nuke_shows ORDER BY pn_showstate
pn_showstate contains a 2 letter state abbreviation for the location of the show. Using this, I can set it to only display states for which it knows of shows happening - this way, I don't have 20 states with (0) shows listed

Then as the loop runs, to find out which states have shows in them, I just call...
while ($data = mysql_fetch_assoc($result)) {
$output->Text('<tr bgcolor="#E3EDD9"><td width="5" align="right" nowrap><font face="Verdana">»</font></td><td width="99%"><a href="'.pnModURL('shows', 'user', 'showlist').'&state='.$data['pn_showstate'].'">'.getstate($data['pn_showstate']).'</a> ('.countshows($data['pn_showstate']).')</td></tr>');
}
- while ($data = mysql_fetch_assoc($result)) {
- $output->Text('<tr bgcolor="#E3EDD9"><td width="5" align="right" nowrap><font face="Verdana">»</font></td><td width="99%"><a href="'.pnModURL('shows', 'user', 'showlist').'&state='.$data['pn_showstate'].'">'.getstate($data['pn_showstate']).'</a> ('.countshows($data['pn_showstate']).')</td></tr>');
- }
On my regular request to get the total count of shows in a given state, it calls this function...
function countshows($state) {
$sql = 'select count(*) from nuke_shows where pn_showstate = "'.$state.'" and pn_showend > "'.(time() + 86400).'"';
$result = mysql_query($sql);
return mysql_result($result, 0);
}
- function countshows($state) {
- $sql = 'select count(*) from nuke_shows where pn_showstate = "'.$state.'" and pn_showend > "'.(time() + 86400).'"';
- $result = mysql_query($sql);
- return mysql_result($result, 0);
- }
and getstate() simply turns a 2 letter state abbreviation into its full name.
Obviously, I don't want to list shows that have already happened.
As you can see in the countshows() function, there is a field called pn_showend. This is a Unix timestamp of the date the show ends (00:00 on that day). I do want listings for those to show up the entire last day of the show, so I set it to not list them on the following midnight in this function.
Now, let's say that a particular state (Florida, in this example), the database has 20 shows, but 16 of them have already happened.
No problem, the function still sees that there are shows in Florida, and countshows() returns the correct number (4 remaining shows).
But, what if there are 20 shows in the database, and ALL of them have already happened. My first loop is still going to see that there are shows in Florida, but countshows() is going to return 0.
Is there a way to modify this request...
SELECT DISTINCT pn_showstate FROM nuke_shows ORDER BY pn_showstate
So that it takes into account the...
where pn_showend > "'.(time() + 86400).'"
bit, and only lists the state if there are still shows that have not yet happend?
Btw, simpy doing...
$sql = 'SELECT DISTINCT pn_showstate FROM nuke_shows where pn_showend > "'.(time() + 86400).'" ORDER BY pn_showstate';
doesn't work, I knew this already, but pasting for those who might suggest it
And this is on MySQL 3.23.56 (I think, just off-hand without checking, I know it's definitely 3.23.something)