Lostnode Posted January 18, 2012 Share Posted January 18, 2012 I am having difficulty wrapping my head around how I can sort things easily. Basically I have a few chunks of code which I will be extracting and making into includes to tidy up my code, but what I am looking for is a way to sort the includes by user preference. For instance say I have 4 include files, incude1.php though include4.php, user 1 wants them to show up 1, 2, 3, 4, user 2 wants them to show up 1, 3, 2, 4 and user 3 wants them to show up 4, 1, 3, 2.... I was thinking about using if statements but that is most definitely not the right way to go. The structure for this would be in the settings table, so they would set their preferences there, but I am stuck on how to get it to physically put things in the right order. I am sorry I have no code to show as I have absolutely no idea of where to start. I am looking for a push in the right direction (then I can post some code when it goes horribly wrong) Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/ Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 $order = '4,2,3,1'; foreach(explode(',' $order) as $o) { include 'include' . $o . '.php'; } How's that? Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/#findComment-1308766 Share on other sites More sharing options...
Lostnode Posted January 18, 2012 Author Share Posted January 18, 2012 Thanks for the quick reply, I will have to think about this a bit more, as my includes aren;t actually called include#.php, they are actually named... worse come to worse, I may have to number them. As for $order, I am not sure how that would work either, as I need to pull the variables from the database... I will test it out tomorrow when I get to the office... Could this work? $order = "$var1, $var2, $var3, $var4"; Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/#findComment-1308767 Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 Well how is it stored in the database? And what does the data actually look like? Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/#findComment-1308770 Share on other sites More sharing options...
Lostnode Posted January 18, 2012 Author Share Posted January 18, 2012 Well how is it stored in the database? And what does the data actually look like? It will be stored as an integer, 1 through as many modules will be created (currently 5 but potentially more) and the variables are descriptive of the module, currently $cpord, $tnord, $dhord, $amord, $feord. the files them selves are name based, canpar.php, tnt.php, dhl.php, aramex.php and fedex.php, This is to grow of course, more includes and more order variables. Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/#findComment-1308772 Share on other sites More sharing options...
scootstah Posted January 18, 2012 Share Posted January 18, 2012 Are the modules stored in the database? You could have the users sort them by their ID, and then just gather the modules from the database, and include them in the right order. Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/#findComment-1308775 Share on other sites More sharing options...
Lostnode Posted January 18, 2012 Author Share Posted January 18, 2012 Are the modules stored in the database? You could have the users sort them by their ID, and then just gather the modules from the database, and include them in the right order. No they are not in the database, that hadn't even occurred to me to do it that way. I will think it over and see if I can come up with a solution, I will post my code if I get into trouble with it. Quote Link to comment https://forums.phpfreaks.com/topic/255261-stuck-on-how-to-easily-sort-items/#findComment-1308778 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.