galvin Posted November 16, 2009 Share Posted November 16, 2009 (I apologize ahead of time if this is simply not enough info for you to give any type of good answer). I am working on developing a site that has a bunch of check box options on one page (about 100 total). The visitor to the site can check two (and only two) checkboxes and then hit a submit button. The code on the next page will query the MySQL database and retrieve info about those two selected items and will then display that info to the visitor. I know how to do that part just fine. But I would like to be able to run a sort of "Admin report" where I can get all the information for EVERY POSSIBLE CHECKBOX combination that a visitor could choose. For example, if the visitor checked box #14 and box #57, the next page would give them some info regarding those two items (box #14 and box #57). But I would like to be able to run a report that brings back that info for every single combination, so the results would have info for... Box #1 - Box #2 Box #1 - Box #3 Box #1 - Box #4 ... and so on, all the way down to ... Box #99 - Box #100. Again, it woould be every possible combination, so we're talking a lot of results here. And I know there are certainly going to be loops involved, but I can't wrap my head around how to approach doing this. If this makes any sense, can anyone give me a general approach to doing this? If you absolutely need to see code to be able to answer this properly, let me know and I'll re-post later. Thanks, Greg Link to comment https://forums.phpfreaks.com/topic/181726-need-a-general-push-in-the-right-direction/ Share on other sites More sharing options...
rlelek Posted November 16, 2009 Share Posted November 16, 2009 Hey there! First...why checkboxes? A few server a good purpose, but why not use something like "select" fields that are intended for a large selection of options. Just saying... Doesn't make sense to me. As for your question... Try to loop (for or foreach) through all 100 and then loop through all 100 within the loop. ex. Looping 1 - 100 Item 1 - Looping 1 - 100 Item 1 Item 2 Item 3... Item 2 - Looping 1 - 100 Item 1 Item 2 Item 3... And so on... This way you can run through all the combinations! If you need help with the syntax/code, try posting back... But please try first!!! Link to comment https://forums.phpfreaks.com/topic/181726-need-a-general-push-in-the-right-direction/#findComment-958463 Share on other sites More sharing options...
galvin Posted November 16, 2009 Author Share Posted November 16, 2009 I wrote this further explanation out before you replied rlelek, so I figured I'd share... MySQL table is has following columns... box# /rank1/rank2/rank3/rank4/rank5/rank6/rank7/rank8/rank9/rank10 So there are 100 lines in the table, but two of them would be... box14 /6/8/2/4/5/6/4/2/3/9 box57 /2/7/3/8/9/5/3/1/2/8 The form submits and puts the two checkbox options the visitor chose into an array and I get the two boxes using... $box1 = $_POST['box'][0]; $box2 = $_POST['box'][1]; Keeping with the example, let's say $box1 = 14 and $box2 = 57. Now I query the database and pull all the info about $box1 (i.e. all 10 ranks) And I pull all the info from the database about $box2 (i.e. all 10 ranks). Then I compare "rank1" for each box. So rank 1 for box 14 is "6" and rank1 for box 57 is "2", so I would give a "vote" to box 57 (since it has a lower rank than box 14.) And I would do 10 comparisons (for each rank) and end up with a final tally of something like 7-3 in favor of Box 57. So the visitor would get info like "For Box 14 vs. Box 57, Box 57 wins 7 to 3": I can do all that fine but now I want a report that will list every combination and who wins and what the vote is. So iI would want it to look like... Box 1 vs Box 2, Box 1 wins 8-2 Box 1 vs Box 3, Box 3 wins 7-3 Box 1 vs Box 4, Box 1 wins 9-1 etc, etc, all the way down to... Box 99 vs Box 100, Box 99 wins 6-4 That's where I imagine a ton of looping comes into play Link to comment https://forums.phpfreaks.com/topic/181726-need-a-general-push-in-the-right-direction/#findComment-958466 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.