My goal is to have two ways to filter the displayed data. The first is how many days back in time to display. The other allowing the user to select the group to display. They should work independently of each other. But also in tandem, select 20 days back for group NSV and only records with both criteria are displayed. But select 20 days back for all groups and that works too.
The first drop-down is a simple HTML select/option setup seen on screen as ‘Show 10 days back’. The other is seen as ‘All Groups’ on the page and is created from a MySQL table. To do this I have this function;
function GroupSelect() {
$g_query = "SELECT DISTINCT b.g_code, concat(b.g_code, ' ', b.g_name) as theGroups FROM skeds AS a, Groups AS b
WHERE a.g_code = b.g_code
ORDER BY b.g_name"; //echo $g_query;
foreach($db_found->query($g_query) as $g_row) {
$bg_code = $g_row['g_code'];
$theGroups = $g_row['theGroups'];
$theGroupsSelect .= "<option value=\"$bg_code\">".$theGroups."</option>";
}
echo $theGroupsSelect;
} // End GroupSelect
This function or at least the query work great and the correct records are selected from the table. The and statements are in HTML.
I want either/or both to run when the ‘Filter’ button is selected. Both drop-down lists are in the same DIV tag (selectDIV) and both use the same and whose name is ‘Filter’. Changing either of the two drop-downs, and clicking on ‘Filter’ would cause the display to change.
The call to the GroupSelect function is down around line 434 and looks like this;
The problem is no matter where I put my PDO database allocation, in the ‘GroupSelect’ function or in the primary function of the page ‘buildlist’ I get a Fatal error. The only difference is where it points in the code that is causing them.
Fatal error: Call to a member function query() on a non-object in .../arhab/hab_launch_list_new.php on line 12
So my first issue is where to put the PDO database allocation so it works for both functions. I’ve tried it in both functions individually, as well as above both functions. No matter where I put it I get the above fatal error, only the line number changes.
I think my issue is related to not understanding how to use the PDO to pull both sets of information. They are both in the same MySQL data base, and both use the “skeds” table. However the larger function also uses two other tables. I also tried making the GroupSelect function stand alone in its own file and calling it with a require_once. But had issues with this concept too.
I’m still trying to learn the best way of doing things in PHP, but I really don’t have anyone local I can ask. If you have the time, please take a look and tell me where I’ve gone horribly wrong with this code.
YES, I know the GroupSelect() function is currently commented out. This is the only way to give you the overall feel of the page. Experience tells me some of you will criticize the way I wrote up this question, other because I forgot some detail, please be kind, I’ll try and answer all questions.
And thank you in advance!