Pythondesigns Posted July 26, 2007 Share Posted July 26, 2007 I am working on a CODE script - the idea behind it is that a user is able to choose which modules he wants to display on his page. When I say a module all I mean is a block of code which is in a seperate CODE file (for example: news.php, weather.php, search.php etc). I have two tables. The first table is called 'modules' and simply contains a list of all the modules. It has ID, status, name, description and filename columns. The filename column is the path to the modules CODE file. The second table is called 'profiles_modules' and has the columns ID, profileID, moduleID, location and order. The modules can be in one of three different locations (held in the 'location' column of the profiles_modules table) on the page which are numbered 1, 2 and 3. Basically what I'm doing is first executing a query to get all the modules belonging to that profileID. Then I'm building up the array $modules to contain all of the data from the query. I then want to be able to loop through the $modules array in three different places on the page and display the appropriate modules. For example in location 1 I want to loop through and display modules with location = 1. In location 2 on the page I want modules with location = 2, etc. I cant get it to work though... Its working for location 1 but not for location 2 or 3. // Profile ID $profile[iD] = 1; // The query $query_modules = $DB->Query("SELECT profiles_modules.location, modules.filename FROM profiles_modules, modules WHERE modules.ID = profiles_modules.moduleID && modules.status = 1 && profiles_modules.profileID = '" . $profile[iD] . "' ORDER BY modules.ID ASC"); // Build $modules array while($array = $DB->FetchArray($query_modules)) { $modules[$array[location]][] = $array[filename]; } echo "<h1>Location 1</h1>"; // Display location 1 modules if(is_array($modules[1])) { foreach($modules[1] as $modulefilename) { // loadmodule() simply includes the file loadmodule($modulefilename, 1); } } else echo "No modules for 1"; echo "<h1>Location 2</h1>"; // Display location 2 modules if(is_array($modules[1])) { foreach($modules[2] as $modulefilename) { // loadmodule() simply includes the file loadmodule($modulefilename, 2); } } else echo "No modules for 2"; echo "<h1>Location 3</h1>"; // Display location 3 modules if(is_array($modules[3])) { foreach($modules[3] as $modulefilename) { // loadmodule() simply includes the file loadmodule($modulefilename, 3); } } else echo "No modules for 3"; I think I might either be building the $modules array wrong or perhaps even the loops are wrong. Any suggestions? Thanks Quote Link to comment 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.