Jump to content

HOW can I accomplish this...!?


dvointeractive

Recommended Posts

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>";
}
?>

Link to comment
Share on other sites

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 »

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

 

:confused:

 

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.