Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Databasing
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 09-10-2009, 01:44 AM
  #1
robkar97
Soldier (Level 11)
 
Join Date: Sep 2007
Posts: 108
iTrader: (0)
robkar97 is an unknown quantity at this point
Grouping together but still accessing all rows?

I've got a database of photos in an online db and would like to offer the users the possibility to group photos together that were shot within the same 5 seconds (meaning they most likely show the same subject).

However, these stacked, hidden subsequent shots that would initially be hidden should be "expandable" by clicking an icon of the "master photo" that acts as a cover for the stack.

But when I use the "GROUP BY" feature, all these "stacked" photos aren't fetched at all from the db at all, and I dont' think I can easily do it afterwards using PHP by fetching all photos since I would also like the user to be able to sort by ANY column in the db (not just date!), for example ISO or aperture, while having this "grouping feature" active...

Will I need to do multiple queries (say one addtional for each stacked photo) - or is there a smarter way?

Rob
robkar97 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 09-11-2009, 06:40 PM
  #2
cmetz1977
Champion (Level 13)
 
cmetz1977's Avatar
 
Join Date: May 2008
Location: Lakeland, FL
Posts: 216
iTrader: (0)
cmetz1977 will become famous soon enough
1 ) Run your query, don't group, just order:

$query = mysql_query( "SELECT `photoid`, `phototime` FROM `album` WHERE `userid` = '$userid' ORDER BY `phototime` ASC", $connection_mysql );

2) As you iterate through your results, compare the times and do a subroutine if subsequent photos fall within your 5 second buffer
PHP Code:
if( $query && mysql_num_rows$query ) )
{
  print( 
"<div class='photogroup'>" );

  while( 
$photo mysql_fetch_assoc$query ) )
  {
    if( !isset( 
$lastphotogrouptimestart ) || ( $photo'phototime' ] - $lastphotogrouptimestart ) > 5 seconds )
    
//I'll let you figure out how to do the math there since I don't know how your time fields are configured
    
{
      if( isset( 
$lastphotogrouptimestart ) ) //print a separator if this isn't the first group of photos
        
print( "</div><div class='photogroup'>\n" );
      print( 
"<img src='{$photo[ 'photoid' ]}' class='mainthumbnail'/>\n" );
    }
    else print( 
"<img src='{$photo[ 'photoid' ]}' class='subsequentthumbnail'/>\n" );


      
$lastphotogrouptimestart $photo'phototime' ];
  }

  print( 
"</div>" );
}
else print( 
"<p>This user doesn't have any photos</p>" ); 
Clearly, this won't compile in PHP so just use my suggestions as a guideline. I'm sure you'll have a ton of your own output adjustments to make as well. Godspeed!
__________________
Never accept Kool-aid from someone who won't drink from the same punch bowl.
cmetz1977 is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart



 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 09:05 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.