I am trying to make some code that checks the database to see which pages are part of a category with a given id, and which categories and pages are part of a section with a given id (and then the code checks if any of that matches the id of the current page). I spent a good amount of time researching how this could be done and then wrote my code, but unfortunately it fails to produce a result.
I really have no idea why. I first thought I might have failed to call the database or make a connection but I see other modules working without that, so I have no clue how I can improve my code.
Here is the code:
Code: Select all
$moap_catpageids = 0;
$database->setQuery("SELECT id FROM jos_content WHERE catid=$moap_catids");
$catpageids = $database->loadResultArray();
$catpageidn = explode(",",$catpageids);
foreach ($catpageidn as $catpageid) {
if ($catpageid == $id) {
$moap_catpageids = 1;
}
}
$moap_sectpageids = 0;
$database->setQuery("SELECT id FROM jos_content WHERE sectionid=$moap_sectids");
$sectpageids = $database->loadResultArray();
$sectpageidn = explode(",",$sectpageids);
foreach ($sectpageidn as $sectpageid) {
if ($sectpageid == $id) {
$moap_sectpageids = 1;
}
}
$moap_sectcatids = 0;
$database->setQuery("SELECT id FROM jos_categories WHERE section=$moap_sectids");
$sectcatids = $database->loadResultArray();
$sectcatidn = explode(",",$sectcatids);
foreach ($sectcatidn as $sectcatid) {
if ($sectcatid == $id) {
$moap_sectcatids = 1;
}
}
Apart from this I do not have any code in my module's php document which refers to the database. The $id variable is defined elsehwere in the code and is not the issue. By echoing the variable that should be filled by the loadResultArray I know that no value is produced.
Please help!