Jump to content

Module Ordering


Pythondesigns

Recommended Posts

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

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.