Jump to content

help needed with php code to filter data via html link


Recommended Posts

Posted

My PHP/MySql skills are very basic - I am able to take snippets of code and workout what to change to suit my needs - but takes a bit of time and a lot of trial and error.

 

I have a php message page/intranet page (thanks to @FragglePete for kindly letting me pinching it)

 

I've mage some changes to the pages and added checkbox array to allow staff to select Year Groups as apart of the data input form with the aim to be able to filter by them.

 

Data added ok and I can amended data - by way of implode and explode of the checkbox data to save the data as Year 7, Year 8, Year 9, etc

 

And this is the bit I am now struggling with.....

 

I want to create clickable links which them filters the data based on the Year Group ticked on the checkboxes.

 

Eg... I have a Year 7 link - when clicked it will filer any messages which has been ticked for Year 7 (regardless if other Year groups have been ticket as well)

 

Hope that makes sense.....

Posted

Have found a slightly easier method by creating a separate PHP file for each Year Group search/filter criteria.

 

So each Year Group has their own page with the code

$query_rsNotices = "SELECT * FROM tblnotices WHERE noticesDateStart <= DATE(NOW()) AND noticesDateEnd >= DATE(NOW()) AND noticesYearGroup like '%7%'  ORDER BY noticesDateStart DESC";

 

which returns correct results for that year group (I just need change noticesYearGroup like '%7%' to for the other year groups).

 

Not pretty or elegant but does the job.

Posted
Could you get the year group from the URL and filter it that way? EG the link website.com/page?year=7 and so on? Then the PHP page checks for that parameter and if it exists then run that query code? You can then make the '%7%' part just whatever parameter was in the URL

 

That would be the way I would like to do it but struggled to do it. - so opted for a page per year group with the sql code filtering on that page.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...