Jumpy09 Posted August 4, 2011 Share Posted August 4, 2011 When I started this I knew it was going to be quite difficult, but as I got further into it... I realized it was just downright evil. Alright so I started with 12 Static Content Boxes populated via a single DB row, but a friend suggested Custom Content Boxes which would allow a user to add information that they could control. Thanks for a nice XSS preventing script, I can allow some HTML or even allow various different types of custom content boxes. The problem is in the sorting, I decided to go with a Serialized Array which cut out the need for an entire Table, a few columns, and puts the Sorting all in one place. The Custom Content Box Title, Content, Content Type, and whatnot will go into the MD Array to be populated on a Switch type basis. In order to do this properly, I have to Nest an additional Switch for the Content Types.. but that isn't much of a concern to me. The problem is I am aiming to allow a user to select 2 or 3 column layout, all depending on what they want. This is where this turns into a problem, updating the new order / placement is going to be the Nightmare. On a two column you would have left and right divs, the content boxes are done 100% to prevent any hiccups.. but I don't really know how to spit out the stuff properly to go from side to side. I have to put the Switch / Nested Switch into a while, for, or foreach to get the proper order, but when working with a 2 or 3 column layout this becomes problematic. <?php /* Layout Array Example $layoutArray [ "1" ] [ "id" ] = 1 ; $layoutArray [ "1" ] [ "side" ] = 1 ; \\ 1 for Left , 2 for Right $layoutArray [ "1" ] [ "order" ] = 1 ; \\ Starting from Right Top to Left Bottom 1 -> #? // For Custom Content ONLY $layoutArray [ "13" ] [ "contentTitle" ] = "My Custom Box" ; $layoutArray [ "13" ] [ "contentType" ] = 1 ; \\ 3 Different Types ATM $layoutArray [ "13" ] [ "content" ] = "<p>This is my content for my CustomBox</p>"; Static Boxes would take up ID 1 -> 12, and the Custom Boxes would get their ID from the Auto-Increment in it's Table! */ /** This is dependent on ordering by Order already! **/ foreach ( $layout as $key1 => $value1 ) { foreach ( $value1 as $key2 ) { if ( $key2 [ "side" ] === 1 ) { Switch ( $key2 [ "id" ] ) { case "1": // 1 to 12 for Static Content break; default: Switch ( $key2 [ "contentType" ] ) { case "2": // 2 and 3 break; default: // 1 } break; } } } } ?> I would have to do this for both of the 2 column layout and all three of the 3 column layout changing the if $side = # from 1 , 2 , or 3. Anyone know a quicker / better way to do this? I may have to move to JS to position everything, but that would be a bit obtrusive. The 1 to 12 content boxes will end up making that a pretty nasty switch, but it is the only way I kind of know how to do it. If there are any mistakes in the code, that is a rough draft.. I have not actually coded the bit of code completely required as I am looking for a more efficient method of doing so. To answer the age old question: Do I absolutely need this? Not really, but it would be pretty cool to offer my potential users the option to alter how the website looks to them. Link to comment https://forums.phpfreaks.com/topic/243770-sorting-from-a-multi-dimensional-array/ Share on other sites More sharing options...
Jumpy09 Posted August 4, 2011 Author Share Posted August 4, 2011 I can spot a few minor mistakes in the code, but it is a basic idea of what I am trying to accomplish. I just don't want to have to repeat going through the Array per column in the layout, but the more I think about it the more I realize I may just have to. Link to comment https://forums.phpfreaks.com/topic/243770-sorting-from-a-multi-dimensional-array/#findComment-1251674 Share on other sites More sharing options...
Jumpy09 Posted August 7, 2011 Author Share Posted August 7, 2011 Alright let me change my question! Is there anything wrong with having 2 or 3 of these type things on a single page? I want to be as unobtrusive into Javascript as possible, so I think this may be my only method for doing what I am planning. Link to comment https://forums.phpfreaks.com/topic/243770-sorting-from-a-multi-dimensional-array/#findComment-1253586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.