dvointeractive Posted October 25, 2010 Share Posted October 25, 2010 I've got a mysql table full of files that have been uploaded through a form...I need this page to spit out an organized list of the files and have them grouped by type and then size. Everything is working right now except that this code doesn't just print out the size one time and then list all files that have that size...it looks like this right now: 600x400 view 001 share » 600x400 view 002 share » 600x400 view 003 share » 600x400 view 004 share » 600x400 view 005 share » WHAT I NEED IS THIS: 600x400 view 001 share » view 002 share » view 003 share » view 004 share » view 005 share » How can I edit the below code to do this!? ANYBODY!? <?php $result = mysql_query("SELECT * FROM files WHERE UnitType = 'standard_flash' AND campaignID = '$campaignID' ORDER BY Width, Height, Revision ASC"); while($row = mysql_fetch_assoc( $result )){ echo '<h4 class="size">'.$row['Width'].'x'.$row['Height'].'</h4>'; echo "<ul class='curr'><li><a href=\"javascript:;\"><strong>view </strong>".$row['Revision']."</a><a href=\"share_file.php?fileID=".$row['fileID']."\"> share »</a><br></li></ul>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2010 Share Posted October 25, 2010 See the following post - http://www.phpfreaks.com/forums/index.php/topic,312770.msg1476717.html#msg1476717 You will need to alter the current category code to use the $row['Width'].'x'.$row['Height'] value. Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1126201 Share on other sites More sharing options...
dvointeractive Posted October 25, 2010 Author Share Posted October 25, 2010 See the following post - http://www.phpfreaks.com/forums/index.php/topic,312770.msg1476717.html#msg1476717 You will need to alter the current category code to use the $row['Width'].'x'.$row['Height'] value. THANK YOU for the quick response!!! I looked it over and did as you said: <?php $result = mysql_query("SELECT * FROM files WHERE UnitType = 'standard_flash' AND campaignID = '$campaignID' ORDER BY Width, Height, Revision ASC"); $current_category = ''; // initialize to a value that will never exist as data while($row = mysql_fetch_assoc($result)){ // test if the category changed if($current_category != $row['Width'].'x'.$row['Height']){ // category changed (or it is the first one detected), output the heading here echo '<h4 class="size">'.$row['Width'].'x'.$row['Height'].'</h4>'; echo "<ul class='curr'><li><a href=\"javascript:;\" onclick=\"updateFlashSwf('".$row['Width']."x".$row['Height']." ".$row['Revision']."','".$row['path']."','".$row['Width']."','".$row['Height']."')\"><strong>view </strong>".$row['Revision']."</a><a class=\"example7\" href=\"share_file.php?fileID=".$row['fileID']."\"> share »</a><br></li></ul>"; // remember the current category for the next test $current_category = $row['Width'].'x'.$row['Height']; } // output the product data here } ?> That gets me a bit closer....but it's now only displaying the first file...like so: 600x400 view 001 share » How can I get it to list the others that are also 600x400 like so: 600x400 view 001 share » view 002 share » view 003 share » view 004 share » view 005 share » Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1126209 Share on other sites More sharing options...
PFMaBiSmAd Posted October 25, 2010 Share Posted October 25, 2010 If you read the code carefully, you will notice the the HEADING is output inside the if(){} conditional statement. The actual data is unconditionally output immediately following the closing } of the if(){} conditional statement. Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1126214 Share on other sites More sharing options...
dvointeractive Posted October 25, 2010 Author Share Posted October 25, 2010 If you read the code carefully, you will notice the the HEADING is output inside the if(){} conditional statement. The actual data is unconditionally output immediately following the closing } of the if(){} conditional statement. THANK YOU FOR YOUR HELP!!!! Your last reply clued me in to what was wrong and now everything works fantastically! curious to know if you're available for freelance projects? I'm in Los Angeles and have been getting requests for PHP/MySQL projects more and more lately... I can pay you your rate via pay pal. I've been looking for a "go to guy" for the random help i've needed for problems like the one you just helped me solve! Let me know what you think! (tried personal msg, but it was blocked) Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1126219 Share on other sites More sharing options...
dvointeractive Posted October 27, 2010 Author Share Posted October 27, 2010 If you read the code carefully, you will notice the the HEADING is output inside the if(){} conditional statement. The actual data is unconditionally output immediately following the closing } of the if(){} conditional statement. Ok, so now i'm experiencing a subtle problem with this.... <?php $result = mysql_query("SELECT * FROM files WHERE hidden='N' AND campaignID = '$campaignID' ORDER BY Client, CampaignName, UnitType, Revision ASC"); $unit_type = ''; // initialize unit type to nothing $width_height = ''; // initialize unit type to nothing while($row = mysql_fetch_assoc($result)){ if($unit_type != $row['UnitType']){ // test if the campaign changed // if campaign changed (or it is the first one detected), output the campaign row here echo '<h3 class="type">'.$row['UnitType'].'</h3>';} $unit_type = ''.$row['UnitType'].'';// remember the current campaign for the next test if($width_height != $row['Width'].'x'.$row['Height']){ // test if the width / height changed echo '<h4 class="size">'.$row['Width'].'x'.$row['Height'].'</h4>'; // if width / height changed (or it is the first one detected), output the heading here $width_height = $row['Width'].'x'.$row['Height'];// remember the current width / height for the next test } echo "<ul class='curr'><li><a href=\"javascript:;\" onclick=\"updateFlashSwf('".$row['Width']."x".$row['Height']." ".$row['Revision']."','".$row['path']."','".$row['Width']."','".$row['Height']."')\"><strong>view </strong>".$row['Revision']."</a><a class=\"example7\" href=\"share_file.php?fileID=".$row['fileID']."\"> share »</a><br></li></ul>"; // output the files here } ?> There are multiple records in my dB that have the same values in the Width and Height columns...such as 800 for width and 600 for height. So it appears as though the code goes through the records...it finds 800 and 600, prints it out, goes to the next record which may be 10x10, prints it out...then goes to the next record which is 800x600 again...and since the width and height technically changed...it prints out the second 800x600 after the 10x10....I need them together. It is giving me: 800x600 view 001 share » 10x10 view 001 share » 800x600 view 002 share » I need: 800x600 view 001 share » view 002 share » 10x10 view 001 share » Might you or anyone else possibly have an idea of how to alleviate this issue?? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1127060 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2010 Share Posted October 27, 2010 Your original query had - ORDER BY Width, Height so that records with the same Width and Height were together in the record set. Why did you remove that from the query? Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1127064 Share on other sites More sharing options...
dvointeractive Posted October 27, 2010 Author Share Posted October 27, 2010 Your original query had - ORDER BY Width, Height so that records with the same Width and Height were together in the record set. Why did you remove that from the query? You are RIGHT! Not sure why or when it disappeared...! Good call. I think i'm good now. THANK YOU! Quote Link to comment https://forums.phpfreaks.com/topic/216781-how-can-i-accomplish-this/#findComment-1127083 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.